Hi all

Just coming back to Django after a long time away, and struggling to
get my head around what should be a trivial concept using the ORM.

Essentially I want to do acheive the following SQL:

SELECT * FROM publisher_history
INNER JOIN publisher_publisher ON publisher_publisher.id =
publisher_history.publisher_id
GROUP BY publisher_id ORDER BY date_time DESC;

My models look like this:

class Publisher(models.Model):
        name = models.CharField(max_length=100, blank=False)

class History(models.Model):
        publisher = models.ForeignKey(Publisher, blank=False)

I've been trying to use object values, but I'm getting duplicate
publishers. Code looks like this:

results = History.objects.values('publisher').distinct()

If I run:

results = History.objects.values('publisher').distinct().order_by()

I don't get duplicates but I don't get the results returned in the
order I expect either.

Any help would be greatly appreciated, I've stared at this for a while
now.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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