Home > Mobile >  Filter queryset by checking two columns if they are equal
Filter queryset by checking two columns if they are equal

Time:04-22

models.py

class Entry(models.Model):
    paid = models.FloatField(blank=True, null=True)
    price = models.FloatField(blank=True, null=True)

I want to get all entries that have paid and price columns the same value. How can I achieve this?

CodePudding user response:

I found a solution for this

from django.db.models import F

Entry.objects.filter(price=F('paid'))

CodePudding user response:

x = 12
Entry.objects.get(paid=x, price=x)

Does this solve your problem??

  • Related