Re: Ordering bookeditions by their rating

2008-11-29 Thread coan
On Nov 30, 1:48 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > The set of associated rating for an entry 'e' are accessible via > e.rating_set. So {{e.rating_set.rating}} will do what you're after. Thank you! {{ e.rating_set.all.count }} gives me the number of votes, and {{e.rating_set.a

Re: Ordering bookeditions by their rating

2008-11-29 Thread Malcolm Tredinnick
On Sat, 2008-11-29 at 03:29 -0800, coan wrote: > > > On Nov 29, 2:45 am, Malcolm Tredinnick <[EMAIL PROTECTED]> > wrote: > > > user.edition_set.order_by('rating__rating') > > > > will do what you want. > > > > Yes! It does! > What an amazing timesaver that small line was :-) > > Is i

Re: Ordering bookeditions by their rating

2008-11-29 Thread coan
On Nov 29, 2:45 am, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: >         user.edition_set.order_by('rating__rating') > > will do what you want. > Yes! It does! What an amazing timesaver that small line was :-) Is it possible to actually access the rating directly from the template? In the

Re: Ordering bookeditions by their rating

2008-11-28 Thread Malcolm Tredinnick
On Fri, 2008-11-28 at 08:24 -0800, coan wrote: [...] > But isn't there a way to get all in one query? > In my head the query would look something like this: > user.edition_set.all().order_by(user__edition__rating) Yes, there is a way to do it like that and I've been wondering why you haven't alr

Re: Ordering bookeditions by their rating

2008-11-28 Thread coan
On Nov 28, 1:50 pm, Peter Bengtsson <[EMAIL PROTECTED]> wrote: > The trick is to use .query.group_by. > Here's an example that will work:: Thank you for taking the time to putting this example together! You are hereby granted the title "django query ninja"! What I was trying to do was perhaps

Re: Ordering bookeditions by their rating

2008-11-28 Thread Peter Bengtsson
The trick is to use .query.group_by. Here's an example that will work:: >>> from collection.models import Edition, User, Rating >>> Rating.objects.all().delete() >>> Edition.objects.all().delete() >>> >>> e1 = Edition.objects.create(title=u'Title1', binding=u'') >>> e2 = Edition.objects.create(ti

Re: Ordering bookeditions by their rating

2008-11-28 Thread coan
On Nov 28, 12:56 pm, bruno desthuilliers <[EMAIL PROTECTED]> wrote: > On 28 nov, 11:07, coan <[EMAIL PROTECTED]> wrote: > What's the point of having two distinct models for Bookcollection and > Rating ??? Looks like mostly redundant to me. Good point, I have considered moving ratings into the

Re: Ordering bookeditions by their rating

2008-11-28 Thread bruno desthuilliers
On 28 nov, 11:07, coan <[EMAIL PROTECTED]> wrote: > I have book editions in my database. Users can rate editions. If they > want, they can also add them to their book collection. > Here is a simplified overview of the models: > > class Edition(models.Model): > title = models.models.CharField(ma

Ordering bookeditions by their rating

2008-11-28 Thread coan
I have book editions in my database. Users can rate editions. If they want, they can also add them to their book collection. Here is a simplified overview of the models: class Edition(models.Model): title = models.models.CharField(max_length=255) binding= models.models.CharField(max_l