Ticket #3635: models.diff

File models.diff, 1.0 KB (added by ludo@…, 8 years ago)
  • newforms/models.py

     
    3636        raise ValueError("The %s could not be changed because the data didn't validate." % opts.object_name)
    3737    clean_data = form.clean_data
    3838    for f in opts.fields:
    39         if not f.editable or isinstance(f, models.AutoField):
     39        if not f.editable or isinstance(f, models.AutoField) or not f.name in clean_data:
    4040            continue
    4141        setattr(instance, f.name, clean_data[f.name])
    4242    if commit:
    4343        instance.save()
    4444        for f in opts.many_to_many:
    45             setattr(instance, f.attname, clean_data[f.name])
     45            if f.name in clean_data:
     46                setattr(instance, f.attname, clean_data[f.name])
    4647    # GOTCHA: If many-to-many data is given and commit=False, the many-to-many
    4748    # data will be lost. This happens because a many-to-many options cannot be
    4849    # set on an object until after it's saved. Maybe we should raise an
Back to Top