tags:

views:

23

answers:

1

blow is my database:

class TestCases(TmstafServerModel):
    name = models.CharField(max_length=30)

class TestRunSummary(TmstafServerModel):
    testResult = models.ForeignKey(TestResult)
    testCases = models.ForeignKey(TestCases)
    platform = models.ForeignKey(Platform)

I want to get data order by testcase's name, such as:

all_fail_case = TestRunSummary.objects.all().order_by('testCases.name')

but it not work, how can i get all records in TestRunSummary which ordering by testCases name? thanks:)

+1  A: 

Use __ instead of . like described in the documentation. Alternatively you can also specify a default ordering for the TestCase model and sort by testCases.

all_fail_case = TestRunSummary.objects.order_by('testCases__name').all()
tux21b
Thank you! Can i ask you why not use TestRunSummary.objects.all().order_by('testCases__name')Since in order condition, it's right to write order_by() after all()thank you!
Yuan
@Yuan - it's redundant - `all` is only useful where you need to definitely have a `QuerySet` (per the documentation at http://docs.djangoproject.com/en/dev/ref/models/querysets/#all)
Dominic Rodger
thanks you very much!:)
Yuan