On Jul 19, 10:52 am, Ryan Osborn <ryan.osbor...@gmail.com> wrote:
> Hi,
>
> I am trying to create a form in which a user can fill out details and
> it will create a parent object and multiple child objects, much like
> the django admin does when you set up a model to be a tabuar inline in
> the admin.py.
>
> I think I have to use inline formsets for this, but when I do this,
> only the forms for the child objects get rendered (i.e. the ones for
> Game, not Match).  Here is the code I have so far:
>
> models.py

> views.py
>
> @login_required
> def ladder_challenge(request, ladder_id):
>     ladder = Ladder.objects.get(id=ladder_id)
>     if request.POST.get('post'):
>         pass
>     BookFormSet = inlineformset_factory(Match, Game)
>     formset = BookFormSet()
>     context = RequestContext(request,
> {'ladder':ladder,'formset':formset})
>     return render_to_response('ladder/challenge.html',context)
>
> ladder/challenge.html
>
> {% extends "base.html" %}
>
> {% block title %}Ladder Challenge{% endblock %}
>
> {% block content %}
> <form action="" method="post">
> {% csrf_token %}
> {{formset}}
> <input type="submit" value="Submit" />
> </form>
> {% endblock %}
>
> I would be very grateful if someone could point out where I am going
> wrong.
>
> Thanks,
>
> Ryan

You're on the right track, but you've only created the formset for the
inline models. You haven't created the main form at all. You just need
a separate form class for the parent object, which is instantiated at
the same time, passed into the template context, and displayed there.
--
DR.

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

Reply via email to