Thanks Malcom, I've used your solution and it simplified 200% what i was trying to accomplish. And guess what, i was able to do what i wanted. There are some things i don't quite understand in python and django but with time and patience i'll get there. but i'm loving this framework!!!
Thanks again for showing me the right "WAY" to do it. Maybe i'll write a mini guide about what i ended up. Its a "complex form" (to me) that maps to 4 tables. Happy new year to all. Jorge Sousa On Dec 22, 2007 4:44 AM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > > > On Fri, 2007-12-21 at 18:38 +0000, Jorge Sousa wrote: > > Hi, > > > > I'm a newby to django and python > > > > I'm trying to create a form (master / detail) editable all the way. > > I'm able to post data in the following format: > > > > request.data = { > > 'id': NN, > > 'name': "John Doe', > > 'detail1.0.cod': 'XX', > > 'detail1.0.descr': "abc", > > 'detail1.1.cod': 'YY', > > 'detail1.1.descr': "abc", > > 'detail1.2.cod': 'ZZ', > > 'detail1.2.descr': "abc", > > . . > > .. > > 'detail1.NN.cod': -----', > > 'detail1.NN.descr': "----" > > } > > If you could slightly rename your submission fields, there is indeed an > easier way to do this. I'm assuming you are using Django's "newforms" > package to create a form class of some kind. The "prefix" attribute that > you can optionally pass to a form's __init__ method can be used to tweak > the names expected by a form's elements. > > Also, since you can happily pass extra information to a form (it will > just ignore it), you will end up with something like the following: > > # Assume MasterForm and DetailForm are your form classes > > def my_view(request, ...): > master = MasterForm(request.POST) > detail_forms = [] > for i in range(XX): # work out XX somehow > detail_forms.append(DetailForm(request.POST, > prefix=str(i)) > # ... (now check is_valid(), etc, as per normal) > > To see how the form element should be named here, have a look at [1], > for example. That's part of the test suite and shows the default naming. > You could also override the add_prefix() in your form so that it returns > something in the format you're expecting from the form submission. > > [1] > > http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms/forms.py#L1228 > > This might all take more than just a couple of minutes to master, since > you said you were just starting out with Django and Python. Like > anything new, doing advanced stuff will require a bit of patience and > experimentation, so just try things out and you'll gradually close in on > a solution. > > Regards, > Malcolm > > -- > No one is listening until you make a mistake. > http://www.pointy-stick.com/blog/ > > > > > -- ------------------------------- Jorge Sousa --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---