This is best explained with an example.

i have a model for Stats

class Stat(models.Model):
    key = models.CharField(max_length=50)
    value = models.TextField()
    pub_date = models.DateTimeField()

so if i create a few stat objects lets say these.

stat1 = Stat(key='total_books_sold', value=100,
pub_date=datetime.datetime.now())
stat2 = Stat(key='total_books_returned', value=10,
pub_date=datetime.datetime.now())
stat3 = Stat(key='avg_foos', value=2.6,  pub_date=datetime.datetime.now
())

i would like to be able to one query and get the latest stat per key
so the query should only return. Even if we insert stats every hour.
It should only return 2 (the latest unique for key).

[<Stat: total_books_sold >, <Stat: total_books_returned>, <Stat:
avg_foos>]

I hope that makes sense. I'll do multiple queries if need be.

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