{{{
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'
)
}),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29682>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
* component: Forms => contrib.admin
* severity: Normal => Release blocker
Old description:
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>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10317 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"d311124be59df64278f3149d68e79ce45b8a6c64" d311124]:
{{{
#!CommitTicketReference repository=""
revision="d311124be59df64278f3149d68e79ce45b8a6c64"
Fixed #29682 -- Fixed admin change form crash if a view-only model's form
has an extra field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:3>
Comment (by Tim Graham <timograham@…>):
In [changeset:"53b9a6654b334917446ef2e22f448645107d3219" 53b9a665]:
{{{
#!CommitTicketReference repository=""
revision="53b9a6654b334917446ef2e22f448645107d3219"
[2.1.x] Fixed #29682 -- Fixed admin change form crash if a view-only
model's form has an extra field.
Backport of d311124be59df64278f3149d68e79ce45b8a6c64 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:4>
Comment (by Jones):
Has another problem:
If I have set this field with readonly.
{{{
@admin.register(ModelA)
class ModelAAdmin(admin.ModelAdmin):
form = ModelAForm
readonly_fields = ('form_field', )
fieldsets = (
('Test', {
'fields': (
'test', 'form_field'
)
}),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:5>
* status: closed => new
* version: 2.1 => 2.2
* resolution: fixed =>
Comment:
Issue is still persist if a field is readonly as described above.
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:6>
* status: new => closed
* version: 2.2 => 2.1
* resolution: => fixed
Comment:
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`.
--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:7>