#29682: Admin change form crashes if a view-only model's form has field not on
the
model
---------------------------------+------------------------------------
Reporter: Jones | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham):
* stage: Unreviewed => Accepted
* component: Forms => contrib.admin
* severity: Normal => Release blocker
Old description:
> - Set permission to user with only view to model
> - Create field in form class
> - Go to django admin view un object created
>
> {{{
>
> class ModelAForm(forms.ModelForm):
>
> class Meta:
> model = ModelA
> fields = '__all__'
>
> form_field = forms.BooleanField(
> label="Form Field",
> required=False,
> widget=forms.CheckboxInput()
> )
>
> class ModelA(models.Model):
> test = models.IntegerField(
> null=True,
> blank=True
> )
>
> @admin.register(ModelA)
> class ModelAAdmin(admin.ModelAdmin):
>
> form = TestForm
>
> fieldsets = (
> ('Test', {
> 'fields': (
> 'test', 'form_field'
> )
> }),
> )
> }}}
New description:
Viewing an existing view-only object crashes with:
{{{
AttributeError at /admin/t29682/modela/1/change/
Unable to lookup 'form_field' on ModelA or ModelAAdmin
}}}
{{{
class ModelAForm(forms.ModelForm):
class Meta:
model = ModelA
fields = '__all__'
form_field = forms.BooleanField(
label="Form Field",
required=False,
widget=forms.CheckboxInput()
)
class ModelA(models.Model):
test = models.IntegerField(
null=True,
blank=True
)
@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
form = ModelAForm
fieldsets = (
('Test', {
'fields': (
'test', 'form_field'
)
}),
)
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.4396417a1fa2ff651df2fad1f61436c9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.