2011-11-07 43 views
1

,我有以下表一表的數據: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() 

如何列出了最古老的首先筆記嗎?

回答

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

這是fully documented

+0

我知道這是完全記錄,但我發現反向查找非常直觀 – Sevenearths