1π
β
In this case, you can simply add a property to your model to call in the template. A custom template tag is probably overkill, because you can accomplish the same result with less code just leveraging the model:
class Bar(models.Model):
score = models.PositiveIntegerField(default=0)
@property
def foo(self):
if self.score >= 42:
return "Oh yes!"
return "Nooo!"
π€Brandon Taylor
Source:stackexchange.com