开发者

django order's problem

开发者 https://www.devze.com 2023-01-11 16:49 出处:网络
blow is my database: class TestCases(TmstafServerModel): name = models.CharField(max_length=30) class TestRunSummary(TmstafServerModel):

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:开发者_如何学C)


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消