2

I have a field in my form that is given an initial data and disabled if a user is staff (admin can choose from a list). I have this field disabled for staff with the code line below.

self.fields[''].disabled = True

After uprading to django 1.11.7 it started raising validation errors. I tried making it read only with

self.fields[''].widget.attrs['readonly'] = True

Css becomes read only, but i can still make changes.

Is this a 1.11.7 bug or something has happened in the changes on how the disabled function works. I couldn't find anything new in the documentation

  • the field you want to disable it, is it a text input/select..?? – mohammedgqudah Nov 15 '17 at 07:38
  • 1) The field is choicefield. 2) The solution doesn't really work, because i need to make it read only when im creating a model. I tried updating with disabled field and it is working fine. It's raising me errors when im trying to create a fresh model with the disabled field. The field IS REQUIRED. Forgot to add that. Its made so that when admin is creating a model, he can't leave it empty. Staff user has the initial data given and the field is made read only. – Julius Tvarijonavicius Nov 15 '17 at 07:48

1 Answers1

0

Not the best workaround but i managed to make it work. On the model field i made it blank=True so it doesn't raise me empty field validation with disabled=True, then in the save method, i assigned the value i needed one more time.