Re: Need help with this basic query (annotate vs aggregate)

2011-03-04 Thread Tomasz Zieliński
On 4 Mar, 01:19, Steven Sacks wrote: > Here is my model: > > class PlaylistTag(models.Model): >     playlist = models.ForeignKey(Playlist) >     tag = models.CharField(max_length=128) >     tag_count = models.PositiveIntegerField(default=1) > > The way this model works is simple. If you add a ta

Re: Need help with this basic query (annotate vs aggregate)

2011-03-03 Thread Steven Sacks
Also, I need to get back Playlist records (hence the select_releated()). -- 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-us

Re: Need help with this basic query (annotate vs aggregate)

2011-03-03 Thread Steven Sacks
If it helps, this is, I believe, somewhat equivalent SQL: SELECT playlist_id, tag, SUM(tag_count) score FROM playlist_tag WHERE tag like '%query%' GROUP BY playlist_id ORDER BY score DESC -- You received this message because you are subscribed to the Google Groups "Django users" group

Need help with this basic query (annotate vs aggregate)

2011-03-03 Thread Steven Sacks
Here is my model: class PlaylistTag(models.Model): playlist = models.ForeignKey(Playlist) tag = models.CharField(max_length=128) tag_count = models.PositiveIntegerField(default=1) The way this model works is simple. If you add a tag to a playlist, and the tag doesn't exist, the tag_c