I have the following models:

class User(models.Model):
    pass

class Item(Models.Mode):
    created = models.DateTime(default=datetime.now)
    user = models.ForeignKey(User, related_name="items")

    class Meta:
        ordering = ("-created",)
        get_latest_by = "created"

So a user can have multiple items. I am presenting a list of users and
the user's most recent item. I currently do some hacks to reduce query
counts. A naive approach is:

{% for u in users %}
   {{ u }} last added {{ u.items.latest }}
{% endfor %}

Is there a way in the ORM to do this in one SQL query, or, at least
some easy way to join the two that I am overlooking?
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to