Django Twitter clone. How to restrict user from liking a tweet more than once?
<p>I'm not sure where to start. Right now, the user can press like as many times they want and it'll just add up the total likes for that tweet.</p>

<p>models.py</p>

<pre><code>class Howl(models.Model):
    author = models.ForeignKey(User, null=True)
    content = models.CharField(max_length=150)
    published_date = models.DateTimeField(default=timezone.now)
    like_count = models.IntegerField(default=0)
    rehowl_count = models.IntegerField(default=0)

    def get_absolute_url(self):
        return reverse('howl:index')

    def __str__(self):
        return self.content 
</code></pre>

<p>views.py</p>

<pre><code>class HowlLike(UpdateView):
    model = Howl
    fields = []

    def form_valid(self, form):
        instance = form.save(commit=False)
        instance.like_count += 1
        instance.save()

        return redirect('howl:index')
</code></pre>

<p>Django Twitter clone. How to restrict user from liking a tweet more than once?</p>

<p>Changed liked_count in my models.py to </p>

<pre><code>liked_by = models.ManyToManyField(User, related_name="likes")
</code></pre>

<p>views.py </p>

<pre><code>class HowlLike(UpdateView):

    model = Howl
    fields = []

    def form_valid(self, form):
        instance = form.save(commit=False)
        instance.liked_by.add(self.request.user)

        instance.like_count = instance.liked_by.count()
        instance.save()

        return redirect('howl:index')
</code></pre>

<p>index.html</p>

<pre><code>{{howl.liked_by.count}}
</code></pre>

python django