django: filter based on values
I need to take a set of values, in this case the foreign key liquorID in
LiquorInStore obtained with values() or values_list() and use them to
filter the results by ID of it's parent db, Liquor and return those to the
webpage.
This is the view, I fear I may not be using the variables correctly.
def store(request, store_id=1):
a = Store.objects.get(StoreID=store_id)
b = LiquorInStore.objects.filter(storeID__exact=a).values('liquorID')
args = {}
args['liquors'] = Liquor.objects.filter(id__exact=b)
args['a'] = a
return render(request, 'store.html', args)
Here is the models file as well in case that helps.
class LiquorInStore(models.Model):
StoreLiquorID = models.AutoField(primary_key=True)
liquorID = models.ForeignKey(Liquor)
storeID = models.ForeignKey(Store)
StorePrice = models.DecimalField('Store Price', max_digits=5,
decimal_places=2)
No comments:
Post a Comment