Skip to content

Commit

Permalink
Simple workaround to ignore FieldDoesNotExist with custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri J. Norden committed Jul 22, 2024
1 parent 5ed6426 commit 6666d72
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions admin_confirm/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.admin.exceptions import DisallowedModelAdminToField
from django.contrib.admin.utils import flatten_fieldsets, unquote
from django.core.cache import cache
from django.core.exceptions import PermissionDenied
from django.core.exceptions import PermissionDenied, FieldDoesNotExist
from django.template.response import TemplateResponse
from django.contrib.admin.options import TO_FIELD_VAR
from django.utils.translation import gettext as _
Expand Down Expand Up @@ -176,13 +176,17 @@ def _display_for_changed_data(field, initial_value, new_value):
if add:
for name, new_value in form.cleaned_data.items():
# Don't consider default values as changed for adding
field_object = model._meta.get_field(name)
default_value = field_object.get_default()
if new_value is not None and new_value != default_value:
# Show what the default value is
changed_data[name] = _display_for_changed_data(
field_object, default_value, new_value
)
try:
field_object = model._meta.get_field(name)
default_value = field_object.get_default()
if new_value is not None and new_value != default_value:
# Show what the default value is
changed_data[name] = _display_for_changed_data(
field_object, default_value, new_value
)
except FieldDoesNotExist:
# Ignore custom fields
pass
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():
Expand Down

0 comments on commit 6666d72

Please sign in to comment.