Risolto errore che impediva il salvataggio in presenza di campi della form
estranei o property dell'adminmain
parent
5a085012c5
commit
075f507412
|
|
@ -28,6 +28,7 @@ from admin_confirm.constants import (
|
|||
CACHE_TIMEOUT,
|
||||
)
|
||||
from admin_confirm.file_cache import FileCache
|
||||
from django.core.exceptions import FieldDoesNotExist
|
||||
|
||||
|
||||
class AdminConfirmMixin:
|
||||
|
|
@ -184,13 +185,18 @@ class AdminConfirmMixin:
|
|||
else:
|
||||
# Parse the changed data - Note that using form.changed_data would not work because initial is not set
|
||||
for name, new_value in form.cleaned_data.items():
|
||||
|
||||
|
||||
# Since the form considers initial as the value first shown in the form
|
||||
# It could be incorrect when user hits save, and then hits "No, go back to edit"
|
||||
obj.refresh_from_db()
|
||||
|
||||
field_object = model._meta.get_field(name)
|
||||
initial_value = getattr(obj, name)
|
||||
try:
|
||||
field_object = model._meta.get_field(name)
|
||||
initial_value = getattr(obj, name)
|
||||
except (AttributeError, FieldDoesNotExist) as e :
|
||||
print(e)
|
||||
continue
|
||||
|
||||
|
||||
# Note: getattr does not work on ManyToManyFields
|
||||
if isinstance(field_object, ManyToManyField):
|
||||
|
|
|
|||
Loading…
Reference in New Issue