#30520: Extra field of ModelForm without label, raises error in InlineModelAdmin
-------------------------------------------+------------------------
               Reporter:  George Tantiras  |          Owner:  nobody
                   Type:  Uncategorized    |         Status:  new
              Component:  Uncategorized    |        Version:  2.2
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 As per [https://stackoverflow.com/questions/56156039/extra-field-of-
 modelform-without-label-does-not-render-in-inlinemodeladmin this] and
 [https://stackoverflow.com/questions/54511865/django-extra-fields-in-
 custommodelform-is-giving-unable-to-lookuup-error-i that] S.O. issues,
 although a ModelForm with an extra field which has no label works at the
 model's change view, it raises an error when the same ModelForm is used
 for an inline:

 models.py:
 {{{#!python
 class Parent(models.Model):
     pass


 class Child(models.Model):
     parent = models.ForeignKey(Parent, on_delete=models.PROTECT)
 }}}

 forms.py:
 {{{#!python
 class ChildForm(forms.ModelForm):
     extra_field = forms.CharField()

     class Meta:
         model = Child
         fields = '__all__'
 }}}
 admin.py:
 {{{#!python
 @admin.register(models.Child)
 class ChildAdmin(admin.ModelAdmin):
     '''The ModelForm renders as expected'''
     form = forms.ChildForm


 class ChildInline(admin.TabularInline):
     '''Here the ModelForm without a label in the extra field, will raise
 error'''
     model = models.Child
     form = forms.ChildForm


 @admin.register(models.Parent)
 class ParentAdmin(admin.ModelAdmin):
     inlines = (ChildInline,)
 }}}
 {{{#!python
      File "/home/venv/lined/lib/python3.7/site-
 packages/django/contrib/admin/utils.py", line 364, in label_for_field
      raise AttributeError(message)
      AttributeError: Unable to lookup 'extra_field' on Child or
 ChildInline
 }}}
 Full error message:
 https://pastebin.com/89MUGchf

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30520>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.b8642c864eceb97d6fad1d2df0b24098%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to