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

class Ladder(models.Model):
    name = models.CharField(max_length=50)

class Player(models.Model):
    user = models.ForeignKey(User, unique=True)
    phone = models.CharField(max_length=12)

class LadderMembership(models.Model):
    ladder = models.ForeignKey(Ladder)
    player = models.ForeignKey(Player)
    position = models.IntegerField(editable=False)

class Match(models.Model):
    ladder = models.ForeignKey(Ladder)
    winner = models.ForeignKey(Player, related_name='wins')
    loser = models.ForeignKey(Player, related_name='losses')
    date = models.DateField()

class Game(models.Model):
    match = models.ForeignKey(Match)
    winner_score = models.IntegerField()
    loser_score = models.IntegerField()

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 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