Skip to content

Commit a3e7ca1

Browse files
dtcooperTrangPham
andauthored
Use model meta to generate verbose name (#54)
Render field names of object rather than the word "None" This is fix for issue #53, since an object may not exist when rendering `templates/admin/change_data.html` - ie, if we're greating a new object when `confirm_add = True` is set on a `ModelAdmin` with the `AdminConfirmMixin`. Also makes sure we send an actual object (not the string "None") to the base template, to remove other instances of the word "None" from the add view. Co-authored-by: T Pham <[email protected]>
1 parent e86e394 commit a3e7ca1

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

admin_confirm/admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ def _change_confirmation_view(self, request, object_id, form_url, extra_context)
428428
**self.admin_site.each_context(request),
429429
"preserved_filters": self.get_preserved_filters(request),
430430
"title": f"{_('Confirm')} {title_action} {opts.verbose_name}",
431-
"subtitle": str(obj),
432-
"object_name": str(obj),
431+
"subtitle": obj and str(obj),
432+
"object_name": obj and str(obj),
433433
"object_id": object_id,
434434
"app_label": opts.app_label,
435435
"model_name": opts.model_name,

admin_confirm/templatetags/formatting.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ def format_change_data_field_value(field_value):
2222
@register.simple_tag
2323
def verbose_name(opts, fieldname):
2424
# opts is set within context and is equal to model._meta
25-
if opts:
26-
return opts.get_field(fieldname).verbose_name
25+
return opts.get_field(fieldname).verbose_name.capitalize()

0 commit comments

Comments
 (0)