Django 2.0.3, Python 3.6.1
I have standard Django admin panel. For one of my model I create list_editable
with some fields (provider
and provider_price
on screenshot). Question is: How to disable those list_editable
fields for edit after some date?
For example, if now is March 11, 2018
and older, fields provider
and provider_price
are disabled and doesn't edit in list view (only in single record change view).
You can use ModelAdmin.get_changelist_form
. Something like this:
class TouristVisaInvitationListForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if should_be_disabled(self.instance.date): # whatever condition you want
self.fields['provider'].disabled = True
self.fields['provider_price'].disabled = True
class TouristVisaInvitationAdmin(admin.ModelAdmin):
.
.
.
def get_changelist_form(self, request, **kwargs):
return TouristVisaInvitationListForm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With