""" Add this method to a custom form to use as an alternative to the save method. When passed an object instance, the it will set values on the model corresponding to matching field names on the form. Example: myobject = MyObject.objects.get(pk=1) form = MyForm(request.POST) if form.is_valid(): form.update_instance(myobject) """ def update_instance(self,instance,commit=True): for f in instance._meta.fields: if f.attname in self.fields: setattr(instance,f.attname,self.cleaned_data[f.attname]) if commit: try: instance.save() except: return False return instance