[Answered ]-Save() on a model instance not update the changed field on related model side

2👍

This is by design. You have to save each instance seperately. requisition.from_inventoryitem actually queries the InventoryItem instance from the database, just to set the quantity.

requisition = Requisition.objects.get(id=1)
requisition.from_inventoryitem.quantity = 500 # this generates another query here!
requisition.from_inventoryitem.save()

or even better, with a single query, single save

inv_item = InventoryItem.objects.get(requisition_set__id=1)
inv_item.quantity = 500
inv_item.save()

best way. single database call:

InventoryItem.objects.filter(requisition_set__id=1).update(quantity=500)
👤Thomas

Leave a comment