#36921: KeyError when adding new objects two relations deep via inlines but the
intermediate model is not registered with the admin
---------------------------------+--------------------------------------
Reporter: Jacob Walls | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: dev
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Sean Helvey):
Eek! I'm not familiar with the triage process but believe this patch would
add an if statement to check for that. It worked for me locally:
{{{
- source_admin =
self.admin_site._registry[source_model]
- form = source_admin.get_form(request)()
- if self.opts.verbose_name_plural in form.fields:
- field =
form.fields[self.opts.verbose_name_plural]
- for option_value, option_label in field.choices:
- # Check if this is an optgroup (label is a
sequence
- # of choices rather than a single string
value).
- if isinstance(option_label, (list, tuple)):
- # It's an optgroup:
- # (group_name, [(value, label), ...])
- optgroup_label = option_value
- for choice_value, choice_display in
option_label:
- if choice_display == str(obj):
- popup_response["optgroup"] =
str(optgroup_label)
- break
+ if source_model in self.admin_site._registry:
+ source_admin =
self.admin_site._registry[source_model]
+ form = source_admin.get_form(request)()
+ if self.opts.verbose_name_plural in form.fields:
+ field =
form.fields[self.opts.verbose_name_plural]
+ for option_value, option_label in
field.choices:
+ # Check if this is an optgroup (label is
a
+ # sequence of choices rather than a
single
+ # string value).
+ if isinstance(option_label, (list,
tuple)):
+ # It's an optgroup:
+ # (group_name, [(value, label), ...])
+ optgroup_label = option_value
+ for choice_value, choice_display in
option_label:
+ if choice_display == str(obj):
+ popup_response["optgroup"] =
str(
+ optgroup_label
+ )
+ break
}}}
How can I help?
--
Ticket URL: <https://code.djangoproject.com/ticket/36921#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019c4e8d8342-3a0a71b8-f235-4d14-9d33-2d1f99b6a0bd-000000%40eu-central-1.amazonses.com.