Hello, I am trying to filter in my template as follows:
- By date with a calendar
- Items (quantityInventory) where there are less than 10
The problem is that I don't know how to add two filters to my view. The filter that is by date works fine in a Function Based Class and the filter for items(quantityInventory) works fine if I use a ListView. But when combining the two filters in my class based view, nothing happens. That is to say that I am not adding the two filters correctly. Do you have any idea how they can be combined?
Summary : both filters work fine separately and in different types of views (class-based function and ListView), the issue is that I don't know how to put both filters together in the same view
view.py
def pendingStock(request):
if request.method == 'POST':
fromdate=request.POST.get('fromdate')
todate = request.POST.get('todate')
searchresult = Inventory.objects.filter(fecha_registro__range=(fromdate, todate))
queryset = Inventory.objects.filter(quantityInventory__lt=10)
return render(request,'ReporteGanancias/reports-pending-stock.html',{'inventory':searchresult,'queryset':queryset})
else:
displaydata = Inventory.objects.all()
return render(request, 'ReporteGanancias/reports-pending-stock.html', {'inventory': displaydata,'queryset':queryset})
models.py
class Inventory(models.Model):
quantityInventory=models.IntegerField(default=0)
def __str__(self):
return f'{self.quantityInventory}'
I don't know if the model that you have put is correct since it does not have a registration date, so the searchresult query would have to give an error. If that field exists, the query would be like this:
The in else you also have it wrong since you don't have the queryset variable.