I have a model called Inventory and I want to filter the quantityInventory column so that it only appears in stock that has less than 10. As I have it, all the data appears, up to 50 and the point in that template is that it only appears what is in small quantity, not all the data.
In summary : Use a conditional if to say that if quantityInventory < 10 it is filtered and in the template it only shows the number of quantityInventory that are less than 10
Can you help me? Thank you
views.py
class pendingStock(ListView):
model=Inventory
template_name = 'ReporteGanancias/reports-pending-stock.html'
context_object_name='inventory'
queryset=Inventory.objects.all()
models.py
class Inventory(models.Model):
STATUS = (
('Ok', 'Ok'),
('Pending', 'Pending'),
)
dealer = models.CharField(max_length=255, blank=True, null=True)
codigoInventory=models.CharField(max_length=255,blank=True)
invoiceNumber=models.IntegerField()
descriptionInventory= models.CharField(max_length=255, blank=True, null=True)
quantityInventory=models.IntegerField(default=0)
unitPriceInventory=models.IntegerField()
minimumInventory=models.IntegerField()
status=models.CharField(max_length=255,choices=STATUS,default='Ok')
fecha_registro = models.DateTimeField(default=datetime.now)
def __str__(self):
return f'{self.dealer}: {self.codigoInventory} {self.invoiceNumber} {self.descriptionInventory} ' \
f'{self.quantityInventory} {self.unitPriceInventory}{self.minimumInventory}{self.status}{self.fecha_registro}'
You can do it this way:
What it does with the __lt at the end is to tell it to filter by quantityInventory less than 10. If you wanted it to be less than or equal, it would be with __lte
You can see more filters available here: https://pythonguides.com/python-django-filter/