Answer the question
In order to leave comments, you need to log in
Django how to make a selection from the database not by fields but by the value of the model method?
There is a People model and it has a get_age method
class People(models.Model):
last_name = models.CharField(max_length=80, blank=True)
first_name = models.CharField(max_length=80, blank=True)
middle_name = models.CharField(max_length=80, blank=True)
gender = models.CharField(max_length=1)
phone = models.CharField(blank=True, max_length=14)
b_date = models.DateField(null=False)
def get_age(self):
today = date.today()
age = today.year - self.b_date.year
if today.month < self.b_date.month:
age -= 1
elif today.month == self.b_date.month and today.day < self.b_date.day:
age -= 1
return age
People.objects.filter('first_name'='Имя')
People.objects.filter(get_age=25)
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