Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango query filter condition
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5787265/django-filter-check-conditions">django filter check conditions</a> </p> </blockquote> <p>here im using </p> <p>age_from:------- age to:-------------- //here ---- is text field date from:------ dat_to:-------------</p> <p>search button // this is my search button.</p> <p>here i matches the conditions with agefrom ,ageto,datefrom date_to please once you go through with below code..</p> <p>now my problem is :(i want the exact for these 3 parts:) gender : o male o female age_from:------- age to:-------------- date from:------ dat_to:-------------</p> <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> <p>and the model is used :</p> <p>class PatientInfo(models.Model): age = models.IntegerField() gender = models.CharField(max_length=200) dateedit = models.DateTimeField()</p> <p>def search(request):</p> <pre><code>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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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