0

I'm trying to make some fields in Django admin read_only based on other fields value on creating and before save the record.

for example cloths model: and it has Boolean field called is_t_shirt when the user start fill the form when he put this indicator True I want to make other fields such as long_of_leg read only and when that indicator False this field will be editable.

All of that before saving and when editing existing or creating new record, may I can called that as real time or run time.

many thanks

Aman Garg
  • 2,507
  • 1
  • 11
  • 21
Hisham
  • 253
  • 1
  • 4
  • 20

1 Answers1

0

I don't think Django has a built in way to set a field as read only before saving. To achieve this you will have to add some custom JavaScript to add an event listener to the checkbox to see when it is checked/unchecked and then set the disabled attribute on the input fields you would like to disable.

Check out these links:

Checkbox Check Event Listener

https://docs.djangoproject.com/en/2.2/ref/contrib/admin/javascript/

Mikey Lockwood
  • 1,258
  • 1
  • 9
  • 22