Tuesday, June 22, 2010

Sorting objects according to a field from a foreign field

I have an issue sorting objects.
First, let me explain the models i'm using:

class Call(models.Model):
...
priority = models.ForeignKey(Priority)

class Priority(models.Model):
title=models.CharField(max_length=30)
description=models.CharField(max_length=255)
weight=models.IntegerField()


I want to sort the calls according to their priority and more exactly the weight assigned
to priority.

I haven't found a way to do that.
I would need something like this:
c=Call.objects.all().order_by('-priority.weight')

Or can i specify the way the Priority class should be sorted?

Thanks,
Benedict

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment