<https://stackoverflow.com/posts/62401646/timeline> I am using django filter package to filter data based on start, end date and class of dues fields defined in my models. The problem is If I select only class_of_fields data is filtered but when I select start and end_date along with class_of_dues no data is filtered below are my codes
*models.py* *class DuesLevy(models.Model): class_of_dues = models.CharField(max_length=30, default=options.CHOOSE, choices=options.CLASS_OF_DUES, blank=True) payment_circle = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CIRCLE) payment_option = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_OPTION) amount = models.DecimalField(max_digits=8, decimal_places=2) transaction_id = models.CharField(max_length=30, null=True, blank=True, editable=False, default=my_rand) payment_channel = models.CharField(max_length=30, default=options.CHOOSE, choices=options.PAYMENT_CHANNEL_TYPE) payment_date = models.DateField() start_date = models.DateField() end_date = models.DateField() date_recorded = models.DateTimeField(auto_now_add=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) description = models.TextField(blank=True, null=True) def __str__(self): return self.amountfilters.py* *from .models import DuesLevy, Userfrom django_filters import widgetsimport django_filters from django import formsfrom django_select2 import forms as s2formsfrom backend import optionsclass DuesFilter(django_filters.FilterSet): class_of_dues = django_filters.CharFilter( widget=s2forms.Select2Widget(choices=options.CLASS_OF_DUES, attrs={'class':'form-control'})) start_date = django_filters.DateFilter(field_name='payment_date', widget=forms.DateInput(attrs={'class':'form-control', 'type':'date'}), lookup_expr='lt',label='Start Date') end_date = django_filters.DateFilter(field_name='payment_date', widget=forms.DateInput(attrs={'class':'form-control', 'type':'date'}), lookup_expr='gt',label='End Date') user = django_filters.ModelChoiceFilter(queryset=User.objects.all(), widget=s2forms.ModelSelect2Widget( attrs={'class': 'form-control'}, model=User, search_fields=['member_id__icontains'], )) class Meta(): model = DuesLevy fields = ('class_of_dues', 'start_date', 'end_date')* *views.py* *class ListMemberDues(LoginRequiredMixin, View): login_url = '/backoffice/' def get(self, request): queryset = DuesLevy.objects.filter(user=request.user) query_filter = DuesFilter(request.GET, queryset) context = { 'form':query_filter.form, 'query':query_filter, } return render(request, 'dashboard/list-member-dues.html', context)* *templates.html* <form class="form-inline d-flex justify-content-around"> <div class="col-sm-3 my-1"> <div class="input-group"> <div class="input-group-prepend"> <div class="input-group-text">Class Of Dues</div> </div> {{ form.class_of_dues }} </div> </div> <div class="col-sm-3 my-1"> <div class="input-group"> <div class="input-group-prepend"> <div class="input-group-text">Start Date</div> </div> {{ form.start_date }} </div> </div> <div class="col-sm-3 my-1"> <div class="input-group"> <div class="input-group-prepend"> <div class="input-group-text">End Date</div> </div> {{ form.end_date }} </div> </div> <button type="submit" class="btn btn-success">Filter</button> {% csrf_token %} </form> {% if request.user %} <div class="row p-3 bg-light"> <div class="col-md-4"> <h3>Account Details</h3> <h4>{{ request.user.first_name }} {{ single.user.last_name }}</h4> <h4>Phone {{ single.user.phone1 }}</h4> <h4>LCDA: {{ request.user.lcda }}</h4> <h4>Zone: {{ request.user.zone }}</h4> <h4>Area: {{ request.user.area }}</h4> </div> <div class="col-md-4"> <img style="width: 200px; height: auto;" src="{{ request.user.additionalprofile.get_image_url }}" alt=""> </div> </div> {% endif %} <table class="table"> <tr> <th>Payment Date</th> <th>Categories</th> <th>Amount</th> <th>Channel</th> <th>Transaction ID</th> </tr> {% if query %} {% for q in query.qs %} <tr> <td>{{ q.date_recorded }}</td> <td>{{ q.class_of_dues }}</td> <td>₦{{ q.amount }}</td> <td>{{ q.payment_channel }}</td> <td>{{ q.transaction_id }}</td> </tr> {% endfor %} {% endif %} </table> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/70b90b97-b046-4fe7-8c3b-e7ca8811549fo%40googlegroups.com.