0

How to make field editable not for all instances in django admin list view. For example if sum exists make some field only for this instance editable.

I tried override ModelForm and add widget but it doesn't work. Also I tried override has_permission function but it doesn't work too.

enter image description here

UPDATE

I found same issue but I don't know how to get model instance for checking in get_list_editable

Django conditional admin list_editable

yaschk
  • 320
  • 1
  • 11

1 Answers1

0

To make field editable not for all instances in django admin list view you should override _construct_form in BaseModelFormSet.

Add this code before return form:

    if kwargs['instance'].status == 0: # check field status
        form.fields['status'].widget.attrs['disabled'] = 'disabled'
yaschk
  • 320
  • 1
  • 11