Django根据另一个表检索表数据

时间:2011-11-07 13:27:56

标签: python django

我有以下表格:

class Note(model):
    note_data = models.ForeignKey(NoteData)
    important = models.BooleanField(default=0)
    deleted = models.DateTimeField(null=True)
    deleted_by = models.ForeignKey(User, null=True)

class NoteData(model):
    created = models.DateTimeField(default=datetime.now)
    created_by = models.ForeignKey(User, null=True)
    note = models.TextField()

如何先列出最早的所有音符?

1 个答案:

答案 0 :(得分:2)

Note.objects.all().order_by('note_data__created')

这是fully documented