Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango filter check conditions
    text
    copied!<p>here im using </p> <pre><code>age_from:------- age to:-------------- //here ---- is text field date from:------ dat_to:------------- search button // this is my search button. </code></pre> <p>here i match the conditions if select age from it will search the age which is greater on the base on date (date from to date_to) similarly for rest of the cases as mention in below code:</p> <p>now my problem is :</p> <pre><code>gender : o male o female age_from:------- age to:-------------- date from:------ dat_to:------------- </code></pre> <p>now how can i write the condition for gender part ,age part and date part.. its bit confusing im getting exactly... help me.. </p> <pre><code>def search(request): age_from = request.POST["age_from"] age_to = request.POST["age_to"] date_from = request.POST["date_from"] date_to = request.POST["date_to"] if age_from: age1 = 1 if age_to: age2 = 1 if date_from: date1 = 1 if date_to: date2 = 1 if age1 and not age2: if date1 and date2: patient = PatientInfo.objects.filter(age__gte=age_from , dateedit__range=(date_from,date_to)) else: if date1: patient = PatientInfo.objects.filter(age__gte=age_from,dateedit__gte=date_from) else: if date2: patient = PatientInfo.objects.filter(age__gte=age_from, dateedit__lte=date_to) else: patient = PatientInfo.objects.filter(age__gte=age_from) if age2 and not age1: if date1 and date2: patient = PatientInfo.objects.filter(age__lte=age_to, dateedit__range=(date_from,date_to)) else: if date1: patient = PatientInfo.objects.filter(age__lte=age_to, dateedit__gte=date_from) else: if date2: patient = PatientInfo.objects.filter(age__lte=age_to, dateedit__lte=date_to) else: patient = PatientInfo.objects.filter(age__lte=age_to) if age1 and age2: if date1 and date2: patient = PatientInfo.objects.filter(age__range=(age_from,age_to),dateedit__range=(date_from,date_to)) else: if date1: patient = PatientInfo.objects.filter(age__range=(age_from,age_to),dateedit__gte=date_from) else: if date2: patient = PatientInfo.objects.filter(age__range=(age_from,age_to),dateedit__lte=date_to) else: patient = PatientInfo.objects.filter(age__range=(age_from,age_to)) if date1 and not date2: if age1 and age2: patient = PatientInfo.objects.filter(dateedit__gte=date_from, age1__range=(age_from,age_to)) else: if age1: patient = PatientInfo.objects.filter(dateedit__gte=date_from, age__gte=age_from) else: if age2: patient = PatientInfo.objects.filter(dateedit__gte=date_from, age__lte=age_to) else: patient = PatientInfo.objects.filter(dateedit__gte=date_from) if date2 and not date1: if age1 and age2: patient = PatientInfo.objects.filter(dateedit__lte=date_to, age1__range=(age_from,age_to)) else: if age1: patient = PatientInfo.objects.filter(dateedit__lte=date_to, age__gte=age_from) else: if age2: patient = PatientInfo.objects.filter(dateedit__lte=date_to, age__lte=age_to) else: patient = PatientInfo.objects.filter(dateedit__lte=date_to) if date1 and date2: if age1 and age2: patient = PatientInfo.objects.filter(dateedit__range=(date_from,date_to), age1__range=(age_from,age_to)) else: if age1: patient = PatientInfo.objects.filter(dateedit__range=(date_from,date_to),age__gte=age_from) else: if age2: patient = PatientInfo.objects.filter(dateedit__range=(date_from,date_to), age__lte=age_to) else: patient = PatientInfo.objects.filter(dateedit__range=(date_from,date_to)) </code></pre> <p>the above code is for age and date part... is working perfectly.... but when comes with three condition it confusing.. not getting </p> <p>please write the code for gender,age and date part.. as above thanx in advance...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload