Risolto errore che impediva il salvataggio in presenza di campi della form

estranei o property dell'admin
main
Davide Borgonovo 2021-09-06 18:14:08 +02:00
parent 5a085012c5
commit 075f507412
1 changed files with 9 additions and 3 deletions

View File

@ -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):