On Fri, Jul 24, 2009 at 5:32 AM, sico<allensi...@gmail.com> wrote: > > Hi, > > I want to be able to edit fields from several different models on the > same form/view. > > The models are related one-to-one... can they be defined as "Inline" > forms in the admin system?? The documentation doesn't make any > mention of using inline forms for anything except parent child > relations so I'm thinking this may cause issues. > > Whats the best way to handle this in a custom view? Do I just simply > define forms for each model, pass them in separately to be displayed > in the template and then validate and save them individually on > saving? The fields would need to be clearly distinguishable to which > model they belong using a prefix which is something that formsets use > to distinguish themselves....
Yes, you'd do it this way. Forms (and formsets too) take a prefix argument which you can use to differentiate between the forms. I think you do not want to validate and save them individually though (I'm sorry if I did not understand you), you probably do not want to save anything until all forms have passed validation: if request.method == 'POST': # initialize forms with request.POST and prefix if form1.is_valid() and form2.is_valid() and form3.is_valid(): # save the data from the individual forms else: # .... return render_to_response('template.html', {'form1': form, 'form2': form, 'form3': form}) > (I actually want to be able to edit multiple records of these in a > grid, but need to be able to edit one first!) Then you'll want to look into formsets, and use their prefix parameter too to make sure that the field names of different formsets don't clash. Matthias --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---