models.py:

class Like(models.Model):
    event = models.ForeignKey(Event)
    user = model.ForeignKey(User) 

    class Meta:
        unique_together = ("event", "user")

Now you can count Likes for a given event

likes = 
Like.objects.filter(event='BizBangBoom').annotate(number_of_entries=Count('entry'))

The unique_together Meta enforces limit of one like per user, per event.

If a user un-likes an event, delete the envent - user record

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db07c5b5-c3c2-4769-8f37-5dd022ca4ad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to