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': "----"
}

In the view that handles de POST
i'm using the following code to isolate the detail data

data = request.POST
details = {}
for key, value in data.iteritems():
    m = re.match('(\w+)\.(\d+)\.(.*)', key)
    if m is not None:
        k, i, f = m.group(1), int(m.group(2)), m.group(3)
        if not d.has_key(k):
            d[k] = dict()
        if not d[k].has_key(i):
            d[k][i] = {}

        d[k][i][f] = value

it transforms POST data in something like
{ detail0 : {
  '0' : { id: XX, descr: 'abc' },
  '1' : { id: YY, ....},
  '2':  { id: ZZ , ....}
}}

and so on, so each row could be fed into a Detail0Form instances for
validation
The above code seem very clumsy to me, but it was the only way i was able to
do it.
Is there an easy way to write it down and use a List instead of a Dict. (I
wasn't able to do it with a List)

Thanks,

Merry Christmas  to all

Jorge Sousa




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

Reply via email to