Django beginner here. I have a many-to-many model and want to update multiple values at once.
This is the model (simplified):
class Inventory(models.Model):
item = models.ForeignKey(Items, models.CASCADE)
player = models.ForeignKey(Players, models.CASCADE)
count = models.PositiveIntegerField()
What I do right now is this:
for key in dict:
change_value = Inventory.objects.get(player=player, item=key)
change_value.count += dict[key]
change_value.save()
At least on my HDD test environment this is very slow. Is there a more efficient way of doing this? In other posts it was suggested to use update instead, so this would be:
for key in dict:
Inventory.objects.get(player=player, item=key).update(count=dict[key])
Would this be faster? Could this be improved even further by updating multiple entries at once? Also, is there an efficient way of adding multiple new entries?