When rendering your form in template, fields enumerating from fieldsets
variable, not from fields. Sure you can redefine fieldsets in your
AdminForm, but then validations will fail as original form class doesn't
have such field. One workaround I can propose is to define this field in
form definition statically and then redefine that field in form's __init__
method dynamically. Here is an example:

class ServiceRoleAssignmentForm(forms.ModelForm):
    test = forms.Field()

    class Meta:
        model = ServiceRoleAssignment

    def __init__(self, *args, **kwargs):
        super(ServiceRoleAssignmentForm, self).__init__(*args, **kwargs)
        # Here we will redefine our test field.
        self.fields['test'] = forms.CharField(label='test2')

On Wed, Apr 20, 2011 at 11:19 AM, sebastien piquemal <seb...@gmail.com>wrote:

> Hi !
>
> I have posted this question on SO :
>
> http://stackoverflow.com/questions/5718838/django-adding-new-form-fields-dynamically-in-admin
>
> As you can see I am not the only one to have this problem. I was
> wondering, could it be reported as a bug ? Or enhancement proposal ?
>
> --
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to