Opened 7 years ago
Closed 6 years ago
#29682 closed Bug (fixed)
Admin change form crashes if a view-only model's form has field not on the model
| Reported by: | Jones | Owned by: | nobody |
|---|---|---|---|
| Component: | contrib.admin | Version: | 2.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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'
)
}),
)
Change History (7)
comment:1 by , 7 years ago
| Component: | Forms → contrib.admin |
|---|---|
| Description: | modified (diff) |
| Severity: | Normal → Release blocker |
| Summary: | Error in view permission with custom model form field → Admin change form crashes if a view-only model's form has field not on the model |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 7 years ago
| Has patch: | set |
|---|
comment:5 by , 7 years ago
Has another problem:
If I have set this field readonly.
@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
form = ModelAForm
readonly_fields = ('form_field', )
fieldsets = (
('Test', {
'fields': (
'test', 'form_field'
)
}),
)
comment:6 by , 6 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → new |
| Version: | 2.1 → 2.2 |
Issue is still persist if a field is readonly as described above.
comment:7 by , 6 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
| Version: | 2.2 → 2.1 |
As far as I'm concerned a custom form field cannot be in the readonly_fields, e.g.
<class 'admin_views.admin.ArticleAdmin'>: (admin.E035) The value of 'readonly_fields[0]' is not a callable, an attribute of 'ArticleAdmin', or an attribute of 'admin_views.Article'.
Please open a new ticket with a sample project if you believe that there is any issue with readonly_fields.
Note:
See TracTickets
for help on using tickets.
PR