Prashant
Prashant

Reputation: 402

how to apply multiple query on multiple queryset in django

I wrote a query which is fetching some details

toll_obj = Toll.objects.filter(driver__profile__invoice_number=(invoice_number))

Here toll_obj can be multiple queryset, one field is common for all objects in qs(toll_obj) that is form_date. So I want to apply one more condition here which is form_date<=today . So what can be the best way to achieve this. Any help would be appreciated.

Upvotes: 0

Views: 246

Answers (2)

Ankita Gupta
Ankita Gupta

Reputation: 583

You can use multiple conditions in a filter method.

import datetime

toll_obj = Toll.objects.filter(driver__profile__invoice_number=(invoice_number), form_date__lte=datetime.datetime.today().date())

Upvotes: 1

user2390182
user2390182

Reputation: 73450

You can use __lte (less then or equal) with a date object

from django.utils.timezone import datetime

toll_obj = toll_obj.filter(form_date__lte=datetime.today().date())

Upvotes: 0

Related Questions