Commit 21930401 authored by Brian Rosner's avatar Brian Rosner
Browse files

Fixed #8353 -- Corrected the case when adminform is not in the context when...

Fixed #8353 -- Corrected the case when adminform is not in the context when rendering {% prepopulated_fields_js %} in the admin. Thanks evan_schulz for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8421 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 15f8b4cd
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -8,13 +8,14 @@ def prepopulated_fields_js(context):
    the prepopulated fields for both the admin form and inlines.
    """
    prepopulated_fields = []
    if context["add"]:
        prepopulated_fields.extend(context["adminform"].prepopulated_fields)
    if context['add'] and 'adminform' in context:
        prepopulated_fields.extend(context['adminform'].prepopulated_fields)
    if 'inline_admin_formsets' in context:
        for inline_admin_formset in context['inline_admin_formsets']:
            for inline_admin_form in inline_admin_formset:
                if inline_admin_form.original is None:
                    prepopulated_fields.extend(inline_admin_form.prepopulated_fields)
    context.update({"prepopulated_fields": prepopulated_fields})
    context.update({'prepopulated_fields': prepopulated_fields})
    return context
prepopulated_fields_js = register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True)(prepopulated_fields_js)