user13115670
user13115670

Reputation:

filter MyDjango data based on condition and calculation in django

class Student():
    name=models.CharField(max_length=200)
    surname=models.CharField(max_length=200)


class groupA():
    name=models.CharField(max_length=200)
    math=models.DecimalField(decimal_places=2,max_digits=1000)
    english=models.DecimalField(decimal_places=2,max_digits=1000)
    biology=models.DecimalField(decimal_places=2,max_digits=1000)
    chemistry=models.DecimalField(decimal_places=2,max_digits=1000)

How to filter the ready list based on type_1 > 2 and type_2 < 1 ?

Upvotes: 0

Views: 44

Answers (1)

JPG
JPG

Reputation: 88499

Something like this,

result = groupA.objects.annotate(
    type_1=F('math') / F('english'),
    type_2=F('chemistry') / F('math'),
).filter(type_1__gt=2, type_2__lt=1)

Upvotes: 2

Related Questions