Reputation: 4008
In Django Admin for a Model I want all fields to be:
For example:
2-1. If attribute a
has a value, the fields corresponding to attributes c
and b
to be readonly
2-2. If attributes are empty after creation, should not be editable on updating
I know that for normal forms there is the Field disabled
attribute.
I know I need to overwrite Admin form, but I don't have an idea, to know is created or update when form is initialized.
Usually I get the value using clean(), but here I need to get them on initialization in case of updates.
Upvotes: 0
Views: 1297
Reputation: 274
So it is like this:
You can create custom FORMS see here https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form
After that you can add your logic of which form to use by overriding the get_form method. see here https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form
However you need to make sure your DB will accept the partially submitted data. You can DROP NULL on the specific columns.
Upvotes: 2