#11850: Intermediate model order not applied to related model
------------------------------------------+---------------------------------
 Reporter:  pielgrzym                     |       Owner:  nobody    
   Status:  new                           |   Milestone:            
Component:  Database layer (models, ORM)  |     Version:  1.1       
 Keywords:  model orderin, many to many   |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 Hi,

 Here is a slightly modified example from django m2m with intermediate
 model docs (note the meta class with order in Membership model):


 {{{
 class Person(models.Model):
     name = models.CharField(max_length=128)

     def __unicode__(self):
         return self.name

 class Group(models.Model):
     name = models.CharField(max_length=128)
     members = models.ManyToManyField(Person, through='Membership')

     def __unicode__(self):
         return self.name

 class Membership(models.Model):
     person = models.ForeignKey(Person)
     group = models.ForeignKey(Group)
     date_joined = models.DateField()
     invite_reason = models.CharField(max_length=64)
     class Meta:
         ordering = ('date_joined')
 }}}


 Now if we try to access the group members (as in django docs):

 {{{
 >>> beatles.members.all()
 [<Person: Ringo Starr>, <Person: Paul McCartney>]
 }}}

 '''They are sorted with order of Person model, not intermediate model. You
 have to manually assign order_by to achieve the desired effect:'''

 {{{
 >>> beatles.members.all().order_by('membership__date_joined')
 }}}

 It would be nice to be able to specify the intermediate order as default
 order for ManyRelatedManager.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11850>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to