SuitUp
SuitUp

Reputation: 3182

How to order descending by a field in a different model in django models?

Here is an example how to order descending:

Entry.objects.filter(pub_date__year=2005).order_by('-pub_date', 'headline')

So we can use: '-pub_date'.
And another example how to order by a field in another model:

Entry.objects.order_by('blog__name', 'headline')

So we can use: 'blog__name'.
How i can do both in one query? 'blog__-name' doesn't work.

Upvotes: 2

Views: 2665

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798526

You want '-blog__name'.

Upvotes: 12

Related Questions