TIMEX
TIMEX

Reputation: 271624

How do I do this "order by" in Django, if I have foreign keys?

Suppose my model is this:

class Ego(models.Model):
    event = models.ForeignKey(Event)
    user = models.ForeignKey(User)

As you can see, this table has 2 columns, and they're both foreign keys. How do I "order by" User.first_name?

Is this it? But it doesn't look like it.

Ego.objects.all().order_by("User.first_name")

Upvotes: 1

Views: 125

Answers (1)

TIMEX
TIMEX

Reputation: 271624

Solved.

I did this:

Ego.objects.all().select_related.order_by("auth_user.first_name")

Upvotes: 3

Related Questions