I have a view that renders data related to a user in template. I am facing an issue with a couple queries but cannot understand the cause. Django documentation unfortunately does not provide example for what I am trying to do. here is what my view looks like:
@method_decorator(login_required, name='dispatch')
class SupplierPage(LoginRequiredMixin,APIView):
def get(self, request, *args, **kwargs):
query = request.GET.get('search_ress', None)
print(query)
context = {}
Supplier = supplier.objects.filter(supplier = query)
labels = Item.objects.filter(fournisseur = query).values_list("reference")[:10]
default_items = Item.objects.filter(fournisseur = query).values_list("number_of_sales")[:10]
label1s = Item.objects.filter(fournisseur = query).values_list('reference', flat=True)[:10]
default_item1s = Item.objects.filter(fournisseur = query).values_list('number_of_orders_placed', flat=True)[:10]
context.update({'Supplier' : Supplier, 'labels':labels, 'default_items':default_items,'label1s':label1s, 'default_item1s':default_item1s})
return render(request, 'Supplier.html',context)
so what is going on is that query
is working fine and in fact Supplier
renders the proper data. but the ones below return empty.
here is what I get in the django log:
DEBUG (0.001) SET search_path = 'pierre','public'; args=None
DEBUG (0.001) SELECT "dashboard_item"."reference" FROM "dashboard_item" WHERE "dashboard_item"."fournisseur" IS NULL LIMIT 10; args=()
DEBUG (0.001) SET search_path = 'pierre','public'; args=None
DEBUG (0.001) SELECT "dashboard_item"."number_of_sales" FROM "dashboard_item" WHERE "dashboard_item"."fournisseur" IS NULL LIMIT 10; args=()
DEBUG (0.001) SET search_path = 'pierre','public'; args=None
DEBUG (0.001) SELECT "dashboard_item"."reference" FROM "dashboard_item" WHERE "dashboard_item"."fournisseur" IS NULL LIMIT 10; args=()
DEBUG (0.001) SET search_path = 'pierre','public'; args=None
DEBUG (0.001) SELECT "dashboard_item"."number_of_orders_placed" FROM "dashboard_item" WHERE "dashboard_item"."fournisseur" IS NULL LIMIT 10; args=()
and in gunicorn:
start 2020-08-25 11:08:17.905545
BOLSEIRA
<QuerySet [<supplier: supplier object (BOLSEIRA)>]>
<QuerySet ['372600', '372750', '372650', '372700', '289807', '372150', '289922', '289840', '289923', '372310']>
<QuerySet [62.0, 58.0, 74.0, 60.0, 1.0, 16.0, 1.0, 1.0, 1.0, 2.0]>
<QuerySet ['372600', '372750', '372650', '372700', '289807', '372150', '289922', '289840', '289923', '372310']>
<QuerySet [4.0, 4.0, 4.0, 5.0, 2.0, 4.0, 2.0, 2.0, 2.0, 2.0]>
start 2020-08-25 11:08:04.890776
None
<QuerySet []>
<QuerySet []>
<QuerySet []>
<QuerySet []>
<QuerySet []>
start 2020-08-25 11:08:06.306851
None
<QuerySet []>
<QuerySet []>
<QuerySet []>
<QuerySet []>
<QuerySet []>
None
<QuerySet []>
<QuerySet []>
<QuerySet []>
<QuerySet []>
<QuerySet []>
start 2020-08-25 11:08:08.460480
gunicorn log is very bizarre, it seems that in a first it works fine and then it stopped. So weird!
I have verified the sintax, the variable names, and also that there is data in the db, and everything is okay, at this point I am out of things to try. I am hoping that someone could see where I am messing up. Thanks!