'I added a Like model but I don't know how to increase the number of like
I created a Blog app, and i want to add a Like button to each post in the Blog, how can i do this ? how can i make this happen in view and the template ?
the models:
class Like(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
post = models.ForeignKey(Photo, on_delete=models.CASCADE)
def __str__(self):
return str(self.user)
the view:
def viewPhoto(request, pk):
post = get_object_or_404(Photo, id=pk)
photo = Photo.objects.get(id=pk)
return render(request, 'photo.html', {'photo': photo, 'post': post })
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
