I’ve created a simple ‘favourites’ system in my django app. I have events which can be faved by any logged in user. What i’m trying to do is somehow check if current logged-in user has faved currently looped event.
It would be quite easy if i could make it in my views.py file but i need to check it directly in template or in a model (in which i can’t get currently logged-in user data).
My Event model looks like that:
...
class Event(models.Model):
...
users_faved = models.ManyToManyField(User, related_name='users_faved', blank=True)
If i would be able to access currently logged in user data from Model, i would create a new object called, for example, is_faved() which would be called from a template that way:
{% for event in evemts_list %}
{{ event.is_faved }}
{% endfor %}
But as i’ve mentioned before, i’m not able to access current logged in user data. Any help would be appreciated! Thanks
Try writing a custom template filter, that takes an event and the user as an argument.