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... On 26/08/2014 8:41 am, "amarshall" <adriand...@gmail.com> wrote:
> Hi, > > I'm trying to implement likes on a Model in which 1 user will be able > to like an a model (named "event") "once" and only once. > > so, I have a model like this: > > class Event(models.Model): > > user = models.ForeignKey(User) > . #other fields > . > likes = models.PositiveIntegerField(default=0,null=True) > > > > > How do I implement it so that only one user can "like" an event (increase > by 1) ? Brainstorming I'm thinking should I make a new class called "like" > and have it have "Event" as a foreign key and a oneToOne relationship with > User ? not really sure how to go about doing this. > > class Like(models.Model): > > event = models.ForeignKey(Event) > > user = model.ManyToMany(User) > user_liked = models.BooleanField(default=false) > total_count = models.PositiveIntegerField(default=0) > > > ? Then when an event is created a "Like" is created as well ? This may > be doing to much and there's a simpler way? > > > > > -- > 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/05ade3fc-f182-49be-a7d3-043fad68131b%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/05ade3fc-f182-49be-a7d3-043fad68131b%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAHqTbjmGzLQ7x06XoWpXhjphv6dP7G3O2%3De3%2BBLqO3da4uoEFA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.