I have 2 models. Product and Favorite (its kind of like)
Favorite has relationship to product and user.
I need to check in templates do a user have relationship with a product for inserting like or unlike button.
class Favorite(models.Model):
"""User favorite products"""
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='favorites')
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='favorites')
class Product(models.Model):
"""Store product"""
...
In template I have:
{% for product in products %}
...
I'd think i can do it like that
{% if product in user.favorites.all %}
But i dont know how to get all favorite products instead of favorites
How i can solve it in templates?