13👍
✅
You can solve it this way:
class RandomForm(ModelForm):
def __init__(self, *args, **kwargs):
super(RandomForm, self).__init__(*args, **kwargs)
if not self.instance:
self.fields.pop('active')
class Meta:
model = models.Service
fields = (...some fields...)
-5👍
Django ModelForm provides exclude
attribute. Have you tried that?
class RandomForm(ModelForm):
class Meta:
model = models.Service
exclude = ['is_active']
- How to write a Django view for a POST request
- Should south migration files be added to source control?
- Django + celery – How do I set up a crontab schedule for celery in my django app?
- ForeignKey to a model that is defined after/below the current model
- How to make a rest_framework Serializer disallow superfluous fields?
Source:stackexchange.com