Django filters two fields in different records with the same value
In Django, I have a large amount of data（real data is about tens of thousands）. I want to find all records with the same amount of income and expenditure. What should I do? Mysql:
I want to filter out data 13467. All expenses and income amounts have the same data (excluding the amount is 0.00)
you can do this:
from django.db.models import F data = Model.objects.filter(income_field=F("expenses_field_name")).exclude(income_field=0)
same question with Datetime Field. Answer
from itertools import chain list_id =  for i in Model.objects.filter(income__gt=0): ids = Model.objects.filter(expenses=i.income).values_list("id",flat=True) list_id.append(ids) #flatten the list of lists list_id = list(set(chain.from_iterable(list_id)))
I want to implement this function, but my data volume is too large, and I don't want to use the for loop to implement it. I want to know if there is a simpler way.