johnny wrote:
> I need to retrieve latest record (each record has a time stamp,
> created_at), only one record, from sale table where product_id=1.  How
> do I do this in Django ORM?  I have looked at .objects.extra{}, but I
> am getting ProgrammingError 1064.
> 
> I need to get this sql into Django ORM:
> 
> select created_at
>       , amount
>       , ...
>   from sales
>   where product_id = 1
> order
>     by created_at desc
>  limit 1

latest = Sale.objects.filter(product_id=1).order_by("-created_at")[0]


  - bram

--~--~---------~--~----~------------~-------~--~----~
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