Robert Johnstone
Robert Johnstone

Reputation: 5371

Django retrieving a tables data based on another table

I have the following tables:

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

How do I list all notes by oldest first?

Upvotes: 1

Views: 83

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599580

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

This is fully documented.

Upvotes: 2

Related Questions