2👍
✅
Don’t reinvent the wheel by constructing your own query and use the power of Django ORM.
For example:
marca = request.POST.get('marca')
modelo = request.POST.get('modelo')
tamano_min = request.POST.get('tamano_min')
latest_products = products.objects.filter(brand=marca, model=modelo, size__gte=tamano_min)
get()
helps to get the value of POST
parameter or None
if no parameter found in the dictionary.
__gte
ending helps to add >=
condition.
You may also want to check marca
, modelo
and tamano_min
before using them:
latest_products = products.objects.all()
if marca is not None:
latest_products = latest_products.filter(brand=marca)
And so on.
Source:stackexchange.com