I want to create a form for editing existing Poll objects and their
associated Choice objects (see below). Editing the Poll objects is no
problem, the 'name' textfield shows up nicely. But I also want to edit
the associated Choice objects with the same form (much like you can do
on the automatically generated admin pages). Although Choices are
related to Polls through a ForeignKey they don't show up in the auto-
generated modelform.

How can I accomplish that? What is the 'sane' way of doing that?

2B

===MODEL========================
class Poll(models.Model):
    name = models.CharField(max_length=200)

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    name = models.CharField(max_length=200)

===FORM========================
class PollForm(forms.ModelForm):

    class Meta:
        model = Poll

===VIEW========================
def edit(request, id):
    poll = Poll.objects.get(id=id)
    if request.method == 'POST':
        form = PollForm(request.POST, instance=poll)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/home/')
    else:
        form = PollForm(instance=poll)
        return render_to_response('edit.html', {'form': form})

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

Reply via email to