5π
β
If the entity you are trying to update is already saved, then you need to provide an instance parameter when you bind the form, otherwise save will try to perform an INSERT rather than an UPDATE, and the new object wonβt validate (check out the django docs here).
Try:
def photo_match(request):
''' performs an update in the db when a user chooses a photo '''
entity = Entity.objects.get(pk=request.POST['entity_id'])
form = EntityForm(request.POST, instance=entity)
form.save()
Youβll want to be a little more robust about the way you look up the entity, of course.
π€meshantz
Source:stackexchange.com