I have a model which has a method called ‘has_voted’. It looks like this…
def has_voted(self, user):
# code to find out if user is in a recordset, returns a boolean
Is it possible to perform this method inside a template? Something like object.has_vote(user)?
You can only call methods with no parameters. So
{{ object.has_voted }}would be OK, if the method was defined simply ashas_voted(self), but as you’ve shown it would not be.The best way to pass a parameter to a method is to define a simple template filter.
and call it: