11👍
✅
Easiest way is to create a filter.
@register.filter
def is_favourite_of(object, user):
return Favourite.objects.is_favourite(user, object)
and in the template:
{% if restaurant|is_favourite_of:user %}
2👍
Maybe I could use the inclusion tag.
Create a tag like that :
{% show_favorite_img user restaurant %}
templatetags/user_extra.py :
@register.inclusion_tag('users/favorites.html')
def show_favorite_img(user, restaurant):
return {'is_favorite': Favorite.objects.is_favorite(user, restaurant)}
- [Django]-Stop django from automatically unicodifing POST stuff
- [Django]-How to make Router display urls from Multiple apps in Browsable API root view in Django REST Framework?
- [Django]-Twilio – generate 6 digit random numbers
0👍
When all else fails you can use the {% expr whatever %} tag to compute a value and stick it in a variable that you can use in your template. I don’t let designers know about it, but sometimes it’s the only thing that works short of standing on your head and … well, you know.
- [Django]-Invalid embedded document instance provided to an EmbeddedDocumentField
- [Django]-How to modify django-ckeditor inline styles?
Source:stackexchange.com