'Filter queryset by checking two columns if they are equal

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?



Solution 1:[1]

I found a solution for this

from django.db.models import F

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

Solution 2:[2]

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

Does this solve your problem??

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 maca2.0
Solution 2 Chymdy