I'm getting a syntax error in the following lines of code. I've imported math, but my update function still won't work. Telling me keyword can't be an expression and cites the bottom 3 lines. Any idea what I'm doing wrong?
StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = liquorID.ShelfPrice)
StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = (float(liquorID.OffPremisePrice)) + (float(S750Increase)))
StoreLiquor.objects.filter(storeID=ID_Store, liquorID.BottleSize='750 ML', custom=False).update(StorePrice = (float(liquorID.OffPremisePrice) * (float(S750Increase)/100)) + float(liquorID.OffPremisePrice))
You can't use dot in arguments names so this part liquorID.BottleSize='750 ML'
causes SyntaxError
to use related models inside filter
use lookups that span relationships
https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships
Django offers a powerful and intuitive way to “follow” relationships in lookups, taking care of the SQL JOINs for you automatically, behind the scenes. To span a relationship, just use the field name of related fields across models, separated by double underscores, until you get to the field you want.
So your statement should looks like this:
StoreLiquor.objects.filter(storeID=ID_Store,
liquorID__BottleSize='750 ML',
custom=False).update(StorePrice=liquorID__ShelfPrice)
I think it should be something like this
StoreLiquor.objects.filter(storeID=ID_Store, liquorID__BottleSize='750 ML', custom=False).update(StorePrice = liquorID__ShelfPrice)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With