Module Expr Str ImportFrom alias ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr Str keyword NameLoad keyword NameLoad keyword Str ClassDef bases body Assign NameStore ListLoad Str decorator_list FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr keyword Num ClassDef bases body Assign NameStore ListLoad Str decorator_list FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad ClassDef bases body Assign NameStore ListLoad Str decorator_list FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad ClassDef bases body Assign NameStore ListLoad Str Str decorator_list FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list decorator_list Assign NameStore Dict Str Str
N/A N/A 
Sorting by related model fields, excerpts from Django queries regression tests.
 django.db models Tag N/A N/A models Model N/A N/A name N/A N/A models CharField max_length 10 N/A parent N/A N/A models ForeignKey self blank True null True related_name children Meta N/A N/A N/A ordering N/A name N/A __unicode__ N/A N/A self N/A N/A N/A N/A self name N/A N/A Note N/A N/A models Model N/A N/A note N/A N/A models CharField max_length 100 N/A misc N/A N/A models CharField max_length 10 Meta N/A N/A N/A ordering N/A note N/A __unicode__ N/A N/A self N/A N/A N/A N/A self note N/A N/A ExtraInfo N/A N/A models Model N/A N/A info N/A N/A models CharField max_length 100 N/A note N/A N/A models ForeignKey Note Meta N/A N/A N/A ordering N/A info N/A __unicode__ N/A N/A self N/A N/A N/A N/A self info N/A N/A Item N/A N/A models Model N/A N/A name N/A N/A models CharField max_length 10 N/A tags N/A N/A models ManyToManyField Tag blank True null True N/A note N/A N/A models ForeignKey Note Meta N/A N/A N/A ordering N/A -note name N/A __unicode__ N/A N/A self N/A N/A N/A N/A self name N/A N/A N/A __test__ N/A API_TESTS 
>>> t1 = Tag.objects.create(name='t1')
>>> t2 = Tag.objects.create(name='t2', parent=t1)
>>> t3 = Tag.objects.create(name='t3', parent=t1)
>>> t4 = Tag.objects.create(name='t4', parent=t3)
>>> t5 = Tag.objects.create(name='t5', parent=t3)

>>> n1 = Note.objects.create(note='n1', misc='foo')
>>> n2 = Note.objects.create(note='n2', misc='bar')
>>> n3 = Note.objects.create(note='n3', misc='foo')

Create these out of order so that sorting by 'id' will be different to sorting
by 'info'. Helps detect some problems later.
>>> e2 = ExtraInfo.objects.create(info='e2', note=n2)
>>> e1 = ExtraInfo.objects.create(info='e1', note=n1)

>>> i1 = Item.objects.create(name='one', note=n3)
>>> i1.tags = [t1, t2]
>>> i2 = Item.objects.create(name='two', note=n2)
>>> i2.tags = [t1, t3]
>>> i3 = Item.objects.create(name='three', note=n3)
>>> i4 = Item.objects.create(name='four', note=n3)
>>> i4.tags = [t4]

Bug #2076
# Ordering on related tables should be possible, even if the table is not
# otherwise involved.
>>> Item.objects.order_by('note__note', 'name')
[<Item: two>, <Item: four>, <Item: one>, <Item: three>]

Bug #7181 -- ordering by related tables should accomodate nullable fields (this
test is a little tricky, since NULL ordering is database dependent. Instead, we
just count the number of results).
>>> len(Tag.objects.order_by('parent__name'))
5

Bug #7791 -- there were "issues" when ordering and distinct-ing on fields
related via ForeignKeys.
>>> len(Note.objects.order_by('extrainfo__info').distinct())
3
