Tuesday, February 1, 2011

Add/Remove fields in ModelForm in Admin site

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'):
self.fields['extra_field'] =
forms.CharField(label='Extra Field')


But debugging, in django/contrib/admin/options.py, in add_view method,
django instantiates my modelform and after that forget it.

I saw many posts googling with solution above - adding fields in
self.fields. Am I doing something wrong or is it not possible in
django 1.2.3 version?

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment