On Sat, Nov 29, 2008 at 4:00 AM, Dominic Ashton <[EMAIL PROTECTED]> wrote: > I have been searching this mailing list, and google, all day and have > come up with very little. I read through the form chapter in Apress > Practical Django Projects (chapter 9) and unbeleivbly in that book > inline forms/sub forms are not covered outside of the Admin. In fact, > when I tend to find any information it is usually somebody trying to > extend the functionality in the admin, which I am not trying to do. > > What I did come up with was to find inlineformset_factory. This seems > to be what i'm after, but it's proving tricky to find a clear and > simple example of its usage, in a context relating to my project, > anywhere on the web.
Did you happen to read the official Django documentation on model formsets? In model formsets there are two factory functions. modelformset_factory and inlineformset_factory. The latter is a subset of the former and makes it easier to work with related objects through a foreign key. Therefore the only different between the two is how you create them, but from then on they take on the same behavior and API. With that in mind read http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1 > > ############## My attempt at a view: ############### > > #project view > def project(request): > if request.method == 'POST': > #form = ProjectForm(request.POST) > form = inlineformset_factory(Project, Project_schedule, > request.POST ) > if form.is_valid(): > form.save() > return HttpResponseRedirect('') > else: > form = inlineformset_factory(Project, Project_schedule, > extra=0) > > return render_to_response('sam_app/project.html', {'form': > form}) > > ############################ > > I understand that the above must be totally incorrect. I'm not getting > any data showing up on my template. Yes, this is wrong. Hopefully by read the documentation I gave you will show you were your problem is. Just to clarify a bit more, inlineformset_factory returns a class. You then instantiate the class to a FormSet instance. During that process you provide it with POST data or any data for that matter. Then the FormSet instance is passed to the template. Also, don't call a FormSet class or instance 'form'. That is just going to be confusing. It is better named FormSet (or some variant depending on the models) for a class and formset for instances. This will help you see the differences and when you are dealing with both. -- Brian Rosner http://oebfare.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

