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