I have an issue where I have something like this:
class Thing(models.Model):
def can_vote(self, user):
if self.vote_set.filter(user=user).count() < 2:
return True
# (A pile of other conditions)
class SomeUser(models.Model):
pass
class Vote(models.Model):
user = models.ForeignKey(SomeUser)
things = models.ForeignKey(Thing)
and I want to do this in a template:
{% if thing.can_vote %}
{# Review stuff #}
{% endif %}
Depending on if the current user has voted less than the amount of times or not. The issue seem to be that Django doesn’t allow you to pass parameters to the method. Is there a way for me to accomplish this neatly?
You can use custom template tag or filter. If filter:
In template: