I have this django code
q1 = MyModel.objects.all()
q2 = MyModel.objects.all()
When I try:
print(q1 == q2)
I get as a result:
False
So how can I check if two querysets results in django are equal?
You can convert the querysets to lists and check whether they are equal:
list(q1) == list(q2)
You can convert it to set, to check if 2 query sets have the same elements, without regard to ordering:
set(q1) == set(q2)
it will return:
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With