On Wed, 2009-02-18 at 09:16 -0800, Thomas Hill wrote: > Hey all, > > Been trying to display multiple form rows for a project lately, and I > just wanted to confirm that I'm doing this right. I found a solution > on http://www.pointy-stick.com/blog/2009/01/23/advanced-formset-usage-django/ > , and I took what I needed from it (my code below), but I found that > whenever I passed in my request.POST data it was getting overwritten > by the users and resource data.
Because your code is saying that the "user" and "resource" values should always be looked up from the database. In the blog post you're referring to, the data that is retrieved from the database is completely orthogonal to the values supplied by the HTML form. Rather, the database values are used to provide things like the quiz question and determine the right answer, whilst the HTML form provides the question answers. If you only want those database values to be used as initial data, it's probably a bit simpler. Pass in "user" and "resource" as initial data values to each subform. That is, you'll want to do the equivalent of r_form = ResourceRoleForm(initial={'user': ..., 'resource': ...}) so you can simplify the ResourceRoleForm.__init__ method, for example. Actually, on closer inspection, it's not quite "user" and "resource" that are the initial data values, but something derived from them. So construct the right initial data values and then in _construct_form() you pass through a dictionary that looks like this: {"initial": {"user": ..., "resource": ...}} I hope that gives you a few hints. If it's still a bit confusing, step away from trying to work with multiple forms all at once. Get it working using initial data and only a single form. Then you'll have your form class working properly and can work out how it should be constructed, which means you can work out what _construct_form() has to pass through. When I wrote my code in that article (in both versions -- the most recent one and the earlier non-formset version), I first worked out what a single form case would look like and then generalised. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---