class Event(models.Model):
user = models.ForeignKey(User)
. #other fields
.
likes = models.PositiveIntegerField(default=0,null=True)
class Like(models.Model):
event = models.ForeignKey(Event)
user = model.ManyToMany(User)
user_liked = models.BooleanField(default=false)
total_count = models.PositiveIntegerField(default=0)
The other way would be to simply wire a cookie to user's browser and use js to disable the the like button if the cookie is present if you can get away with it. Not sure if you need to store that info against the user to see which items they liked...
--
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...@googlegroups.com.
To post to this group, send email to django...@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/05ade3fc-f182-49be-a7d3-043fad68131b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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