[Django] #21464: readonly_fields is not resetted correctly

1 view
Skip to first unread message

Django

unread,
Nov 19, 2013, 3:07:03 AM11/19/13
to django-...@googlegroups.com
#21464: readonly_fields is not resetted correctly
-------------------------------+--------------------
Reporter: fiomtec@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I have a model with three fields, one is a FileField, two I just complete
myself on POST. The next time you see this model, every field is read
only.

This is what I do in the modelAdmin:


{{{
def get_form(self, request, obj=None, **kwargs):
if obj:
self.fields = ('tipo', 'fecha', 'fichero')
self.readonly_fields = ('tipo', 'fecha', 'fichero')
else:
self.fields = ('fichero',)
}}}

Problem is: I create a new object, I enter and see this object, and when I
try to create a new one, readonly_fields is still as it was in the first
object, i.e., I need to do this for the form to allow me to upload a new
file:


{{{
def get_form(self, request, obj=None, **kwargs):
if obj:
self.fields = ('tipo', 'fecha', 'fichero')
self.readonly_fields = ('tipo', 'fecha', 'fichero')
else:
self.fields = ('fichero',)
self.readonly_fields = ()
}}}

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

Django

unread,
Nov 19, 2013, 4:15:53 AM11/19/13
to django-...@googlegroups.com
#21464: readonly_fields is not resetted correctly
-------------------------------+--------------------------------------
Reporter: fiomtec@… | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.5
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by alasdair):

* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0


Comment:

`readonly_fields` is a class variable, it should not be changed from
request to request.

There is a
[https://docs.djangoproject.com/en/1.6/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields
get_readonly_fields] hook that you could use instead. Please use the
support channels if you need more help with this.

wiki:TicketClosingReasons/UseSupportChannels

--
Ticket URL: <https://code.djangoproject.com/ticket/21464#comment:1>

Reply all
Reply to author
Forward
0 new messages