Answer the question
In order to leave comments, you need to log in
How do I call a function in a filter?
Let's say I have a model in models
class User(AbstractUser):
last_online = models.DateTimeField(verbose_name='Online', blank=True, null=True)
def is_online(self):
if self.last_online:
return (timezone.now() - self.last_online) < timezone.timedelta(minutes=15)
return False
def get_online_info(self):
if self.is_online():
return translator.translate(_('Online'))
if self.last_online:
return translator.translate(_('Last visit {}').format(naturalday(self.last_online)))
return _('Unknow')
def get_online(self):
if self.is_online():
return True
else:
return False
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question