[Answer]-Add a custom method in Django model to know if the current user is the author

1πŸ‘

βœ…

It is very sad but you cant pass params to methods from templates(indeed this is a good idea – so you don’t mix presentation logic with model logic, almost πŸ™‚ ). You have to write a template tag for this purpose.

https://docs.djangoproject.com/en/dev/howto/custom-template-tags/

tag would look like this(not tested):

@register.simple_tag(takes_context=True) #  assuming you are running in request context
def current_user_is_creator(context,article):
    user = context['request'].user
    return article.creator.user == user  #  dont forget to add proper checks

Or you could prepare required data in the view.

πŸ‘€singer

Leave a comment