On Jun 22, 3:34 pm, Benedict Verheyen <benedict.verhe...@gmail.com>
wrote:
> 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

As described in the documentation [1], you use the double-underscore
syntax for sorting across relationships.
    Call.objects.all().order_by('-priority__weight')

[1]:http://docs.djangoproject.com/en/1.2/ref/models/querysets/#order-
by-fields
--
DR.

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

Reply via email to