id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 23501,remove/add fields programatically in modelform fails in admin,hadisunyoto,nobody,"model: {{{ class Thickness(models.Model): value = models.DecimalField(primary_key=True, max_digits=7, decimal_places=2) is_active = models.BooleanField() }}} model form: {{{ class ThicknessForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ThicknessForm, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) # edit if instance and instance.pk: del self.fields['value'] else: del self.fields['is_active'] class Meta: model = Thickness fields = '__all__' }}} admin: {{{ class ThicknessAdmin(admin.ModelAdmin): list_display = ('value', 'is_active') form = ThicknessForm admin.site.register(Thickness, ThicknessAdmin) }}} refresh page, go to admin->Thickness, create one: KeyError at /admin/thicknesses/thickness/add/ ""Key 'is_active' not found in 'ThicknessForm'"" ... Error during template rendering In template D:\env\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 7 The highlighted line is number 7 6 {% for line in fieldset %} 7