Friday, August 19, 2011

Re: Dynamic Forms with Varying init Arguments

On Aug 19, 1:58 pm, SixDegrees <paulcarli...@comcast.net> wrote:
> I'm no longer at the computer where my code resides. But "you are wanting to
> call formset_factory
> and have it pass along a parameter to the Form that the formset
> contains" is pretty much what I want to know how to do.

Well, the short answer is that you can't do that--formset_factory()
does not accept kwargs.

Your other option is to basically write your own formset_factory().
If you look at the source, you will see that it really doesn't do
anything special--it's more of a convenience method that creates a
basic FormSet. You could also write your own Formset, with its own
custom __init__ method, inherit from BaseFormSet, and pass that to the
formset_factory() method. Yeah, that's probably what I would do.

A good rule of thumb that I have found is that if you are trying to do
something with Django, and it is either not possible or requires a
good bit of hackery, then you are probably (although not always)
"doing it wrong". Most of Django is very flexible, but sometimes you
just need to know where to look for the answer. That's why I was
inquiring about exactly what your code is doing and such--your use of
a primary key makes me think (but doesn't guarantee) that you are
using a form to represent an instance of a model, and if so, you want
to be looking there.

Wayne

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate