[Fixed]-Django – Access to ForeignKey in template, but with a filter

1👍

There may be a better way, but the way I do it is first get the warehouse object

warehouse_1=Warehouse.objects.get(id=1)

and now get the quantity from ProductStock

products=ProductStock.objects.filter(warehouse=warehouse_1)

Then you can loop through this resulting query set to get what you want

for product in products:
    if product.subcategory.id != '10':
        print str(product.product.name) + " " + str(product.quantity)

Does that work?

Leave a comment