Hello guys.

I think I'm missing some trivial here,

I'm adding dynamic inputs to my form, using JSs, and need to save them.

My problem is:
   for x in information_obj.keys():
      for y in information_params[x].keys():
         information_param = y + ' = "' + y + '"'
         information_obj[x].information_param =  information_params[x][y]
      information_obj[x].save()
      print information_obj[x].information_param
      print information_obj[x].entity

entity is my object attribute
the first "print" prints the right value
the second prints None

So, the save() method don't work, I mean, it works, but I can't put
information_params[x][y] into entity

I also tried using  information_obj[x].y =  information_params[x][y],
still not working.

Btw, there is some way more 'clean' to save dynamic forms ?
I have a Formset from a model, and N forms from other models inside
the same <form>

I'm parsing in a view the IDs/models of inputs in the request.POST...
ex: obj_KEY_ID-fieldname

obj is my model
key is the ForeignKey hash
ID is my model id

I don't know if this second part is clear for you...
I'm thinking the code is to ugly:

                for x in request.POST.keys():
                        for y in [ 'education_'+key+'_', ]:
                                if not x.startswith(y):
                                        continue
                                information_data[x] = request.POST[x]

                information_obj = {}
                information_params = {}
                INFORMATION_handler = {
                        'education': Education,
                        }
                for x in information_data.keys():
                        information_uniq = x.split('-')[0]
                        information = information_uniq.split('_')[0]

                        key = information_uniq.split('_')[1]
                        information_pk = information_uniq.split('_')[2]
                        information_name = x.split('-')[1]
                        if not information_obj.get(information_uniq):
                                information_obj[information_uniq] =
get_object_or_404(INFORMATION_handler[information],
                                 pk=information_pk, status=1)
                                information_params[information_uniq] = {}

information_params[information_uniq][information_name] =
information_data[x]

                for x in information_obj.keys():
                        for y in information_params[x].keys():
                                information_param = y + ' = "' + y + '"'
                                information_obj[x].information_param =
 information_params[x][y]
                        information_obj[x].save()


Thank you very much.

Cheers!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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