Making a field readonly in Django Admin, based on another field's value
django, django-forms, django-models
Solution
You can override the admin's `get_readonly_fields` method:
class MyAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None):
if obj and obj.another_field == 'cant_change_amount':
return self.readonly_fields + ('amount',)
return self.readonly_fields
Problem
How to make a field in Django Admin readonly or non-editable based on the value from another field? I have used `readonly_fields=('amount',)` but this wont fix my problem , as I need to manage it based on another field .