This is going to sound pretty ridiculous but I am having an issue
saving a ManyToMany relationship through a post.  I stripped my app
down to the most basic example from the tutorial.

Applicable Model Code: (I have forms and an Author, but those populate
just fine.  So I already have a few authors created)

class Book(models.Model):
    name = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)

class BookForm(ModelForm):
    class Meta:
        model = Book

Applicable View:
def save(request):
        form = BookForm(request.POST)
        form.save()
        return HttpResponse("save success")

For background purposes:
1. The BookForm shows up just fine in my browser.
2. Within the "authors" section of the BookForm in my browser, I see
the test authors I created.
3. I checked the post parameters and the post parameter 'authors'
correctly contains the ID's of the Authors I selected in the form.

I know this is ridiculously stupid, but I have been struggling with
this.  I see that the "form.save()" method saves to the Book table,
but not the ManyToMany attributes.  I was reading that you first have
to save the Book (to get the PK) then you can save the ManyToMany
relationships.  What's the best way to do this?

Thanks in advance,
MM

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