Re: Add/Remove fields in ModelForm in Admin site

2011-02-02 Thread andmart
Finally , I got it. class ItemForm(ModelForm): item = forms.CharField(label='Item') class Meta: model=Item def __init__(self, *args, **kwargs): super(ItemForm, self).__init__(*args, **kwargs) if kwargs.has_key('instance'): del self.fields['item']

Re: Add/Remove fields in ModelForm in Admin site

2011-02-01 Thread andmart
There is an error in code above. I forgot to write to message the call to super. Here is the code I'm trying to work http://dpaste.com/375663/ Thanks in advance for any help On 1 fev, 17:48, andmart wrote: > Hi all, > > I'm trying to remove or add fields based in presence

Add/Remove fields in ModelForm in Admin site

2011-02-01 Thread andmart
Hi all, I'm trying to remove or add fields based in presence of 'instance' parameter in ModelForm __init__ like this: class ItemForm(ModelForm): class Meta: model = Item def __init__(self, *args, **kwargs): if not kwargs.has_key('instance'):