Showing posts with label Filter Records from Multiple Fields. Show all posts
Showing posts with label Filter Records from Multiple Fields. Show all posts

Tuesday, 22 November 2011

Filter Records from Multiple Fields

this could be bit confusing that how to filter search records from multiple field from Model in django.

To filter records that contain "HJ" in Vendor field and their Rate are 0.14 then Query will be:
obj = TBR.objects.filter(Vendor__contains = "HJ", Rate = 0.14) OR
obj = TBR.objects.filter(Vendor__contains = "HJ").filter(Rate = 0.14)

To filter records that contains "HJ" in vendor field or their Rate are 0.14 then Query will be like this:
obj = TBR.objects.filter(Vendor__contains = "HJ") | TBR.objects.filter(Rate = 0.14)

Best of Luck