Wiadomość napisana w dniu 2008-09-02, o godz. 16:23, przez mwebs:

>
> Hello,
>
> I want to perform a lookup an getting the object with the highest
> integer value.
> The Model looks something like this:
>
> MyModel:
>  name = ....
>  number = models.PositiveIntegerField()
>
>  class Meta:
>     ordering = [-number]
>
>
> So I figured out this:
>
> highest = MyModel.objects.all()[0]
>
> Is there another, more elegant way like: highest =
> MyModel.object.filter(max(number)), so that I dont have to add the
> ordering-attribute in the medta-class?


Sure, you can always specify ordering using order_by(). Ordering  
defines default ordering, where no ordering is specified.

-- 
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
[EMAIL PROTECTED]


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to