On Wed, Aug 20, 2008 at 9:34 AM, patrickk <[EMAIL PROTECTED]> wrote:
>
> ok. I know how to use BaseFormSet, but how do I override
> _construct_form resp. how do I pass the parameters. btw, it seems
> quite odd to override _construct_form when usually one has to override
> __init__.
>

You need to understand the level of abstraction here. Of course the
API can be improved to provide a way to pass custom parameters to the
forms, but certainly that would seem prohibiting and people will
eventually need to override something.

It is basic Python OO at this point. Subclass _construct_form and call
the parent method. The signature of _construct_form allows you to pass
your own keyword arguments to the form in which case this is what you
would do with your two arguments.

class MyBaseFormSet(BaseFormSet):
    def _construct_form(self, i, **kwargs):
        kwargs["my_own_argument"] = "my value"
        return super(MyBaseFormSet, self)._construct_form(i, **kwargs)


>
> On Aug 20, 5:21 pm, "Brian Rosner" <[EMAIL PROTECTED]> wrote:
>> On Wed, Aug 20, 2008 at 9:10 AM, patrickk <[EMAIL PROTECTED]> wrote:
>>
>> > my upload form looks like this:
>>
>> > class UploadForm(forms.Form):
>>
>> >    def __init__(self, path_server, path, *args, **kwargs):
>> >        self.path_server = path_server
>> >        self.path = path
>> >        super(UploadForm, self).__init__(*args, **kwargs)
>>
>> >    file = forms.FileField(label="File")
>> >    use_image_generator = forms.BooleanField()
>>
>> >    def clean_file(self):
>> >        ...
>>
>> > now, I´d like to use UploadFormSet = formset_factory(UploadForm,
>> > extra=5).
>> > question is: where do I set path_server & path?
>>
>> You must subclass django.forms.formsets.BaseFormSet and override
>> _construct_form to pass in your parameters. Then you can pass your
>> FormSet subclass as the base of the FormSet returned by
>> formset_factory like so: formset_factory(UploadForm,
>> formset=BaseUploadFormSet, extra=5).
>>
>> --
>> Brian Rosnerhttp://oebfare.com
> >
>



-- 
Brian Rosner
http://oebfare.com

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to