> > I did read this documentation, and was confused because I read this: > > >>> from django.forms.models import inlineformset_factory > >>> BookFormSet = inlineformset_factory(Author, Book) > >>> author = Author.objects.get(name=u'Orson Scott Card') > >>> formset = BookFormSet(instance=author > > And thought, "ok, that works great in the interpreter, but how do I > put it into my system?" Does it go in forms.py? views.py? > > If it's forms.py, how do I structure it? > > I guess I'm just not getting it. Will try a load of trial and error > this evening see if I can get something to work. > > Cheers, > > Dominic
Ok, I see this must be initiated just as shown in the documentation, in the views.py file. I have managed to get this far: from django.forms.models import inlineformset_factory #project view def project(request): ModelForm = inlineformset_factory(Project, Project_schedule) if request.method == 'POST': form = ProjectForm(request.POST) project = Project.objects.get(pk=request.pk) formset = ModelForm(instance=project) if form.is_valid(): form.save() return HttpResponseRedirect('') else: form = ProjectForm() formset = ModelForm() return render_to_response('sam_app/project.html', {'form': form, 'formset': formset}) At least I can now initialize a blank model inlineformset. However, I can't for the life of me work out how to tie the two together so that I can: 1) Validate both sets of data 2) save both to the database. As you can see, I tried request.pk, which I realize is really stupid as how can the thing have a PK when it's not even saved in the db? When I realized that, I hit a mental brick wall because without access to the pk how am I going to work with relations? Does the way to solve this involve: 1) saving the parent data (if it validates) 2) retrieve the pk from the db 3) use that pk to save the child data (if it validates) If so, what prevents the system from retrieving the incorrect pk, say in the case of heavy concurrent access of the db? This is all a bit confusing for a noob. If there was some kind of example code to look at I feel it would really help. I tried to dig through the admin code but found it a little heavy to follow. Cheers, Dominic --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---