[Django] #29682: Error in view permission with custom model form field

22 views
Skip to first unread message

Django

unread,
Aug 17, 2018, 9:18:18 AM8/17/18
to django-...@googlegroups.com
#29682: Error in view permission with custom model form field
--------------------------------------+------------------------
Reporter: Jones | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 2.1
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 |
--------------------------------------+------------------------
- 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'
)
}),
)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29682>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 17, 2018, 11:46:17 AM8/17/18
to django-...@googlegroups.com
#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:

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

unread,
Aug 18, 2018, 4:20:46 PM8/18/18
to django-...@googlegroups.com
#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: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/10317 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29682#comment:2>

Django

unread,
Aug 20, 2018, 11:42:19 AM8/20/18
to django-...@googlegroups.com
#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: closed
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Aug 20, 2018, 11:50:42 AM8/20/18
to django-...@googlegroups.com
#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: closed
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Django

unread,
Oct 26, 2018, 9:58:56 AM10/26/18
to django-...@googlegroups.com
#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: closed
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Django

unread,
Dec 16, 2019, 6:59:10 AM12/16/19
to django-...@googlegroups.com
#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.2
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by fu2re):

* 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>

Django

unread,
Dec 16, 2019, 7:29:25 AM12/16/19
to django-...@googlegroups.com
#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: closed
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by felixxm):

* 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>

Reply all
Reply to author
Forward
0 new messages