> 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_count is 1. If you add the same tag
> again to that playlist, the tag_count is incremented. If you remove
> that tag, it is decremented. If it reaches 0, I remove the row
> entirely.
>
> A playlist can have multiple tags and a tag can belong to different
> playlists.
>
> (...)
>
> Does this make sense?
IMHO - no, that doesn't make sense :-)
What you need fior the start - and in fact write about - is:
playlists = ManyToManyField(Playlist)
and no `tag_count` field, unless you want denormalize your schema -
which you probably don't.
To count tags for given playlist, you simply do:
playlist.playlisttag_set.count()
Last but not least, looking at your SQL query it might be that I don't
quite get what you need.
--
Tomasz Zielinski
pyconsultant.eu
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment