Tuesday, June 22, 2010

Re: Sorting objects according to a field from a foreign field

On 22/06/2010 16:42, Daniel Roseman wrote:
>
> 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.
>

Thanks for the quick response.
Hhhm, i searched the docs and didn't see it.

Anyway, i'll try your solution.

In the mean time i found another solution:

- Change the model by adding a default ordering via the Meta class

class Priority:
class Meta:
ordering = ('weight',)

Then this works:
Call.objects.all().order_by('-priority')

Regards,
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