On Tue, Mar 5, 2013 at 11:40 AM, Witold Greń <witold.g...@gmail.com> wrote:
> I need to create two formset (generic_inlineformset_factory). When i create
> formset in template used formset_create_company and formset_create_private,
> field names are the same.
>
>     c['form_create_company'] = User1()
>
>     c['form_create_private'] = User2()
>
>     c['formset_create_company'] = generic_inlineformset_factory(SpecialData,
> form=SpecialDataForm, extra=1, max_num=2)
>
>     c['formset_create_private'] = generic_inlineformset_factory(SpecialData,
> form=SpecialDataForm, extra=1, max_num=2)
>
>
> {{ form_create_company.name }} = created: '<input
> id="id_core-specialdata-content_type-object_id-0-name" maxlength="200"
> name="core-specialdata-content_type-object_id-0-name" type="text">'
> {{ formset_create_private.name }} = created: '<input
> id="id_core-specialdata-content_type-object_id-0-name" maxlength="200"
> name="core-specialdata-content_type-object_id-0-name" type="text">'
>
> I need:
>
> {{ form_create_company.name }} = created: '<input
> id="id_my_name1-specialdata-content_type-object_id-0-name" maxlength="200"
> name="my_name1-specialdata-content_type-object_id-0-name" type="text">'
> {{ formset_create_private.name }} = created: '<input
> id="id_my_name2-specialdata-content_type-object_id-0-name" maxlength="200"
> name="my_name2-specialdata-content_type-object_id-0-name" type="text">'
>
>

Ah, I see. generic_inline_formset returns a type, not an instance, so
I'm not sure how your "c['formset_create_company']", which is a type,
not an actual form instance, is used. However, the simple answer is
that a type derived from FormSet will take 'prefix' as an argument
during construction. So, wherever you are constructing the formset,
provide the prefix.

Eg:

SpecialDataInlineFormSet = generic_inlineformset_factory(SpecialData,
form=SpecialDataForm, extra=1, max_num=2)

c['formset_create_company'] = SpecialDataInlineFormSet(prefix='company')
c['formset_create_private'] = SpecialDataInlineFormSet(prefix='private')


Cheers

Tom

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


Reply via email to