django updating m2m field

Posted by Marconi on Stack Overflow See other posts from Stack Overflow or by Marconi
Published on 2010-05-03T12:18:37Z Indexed on 2010/05/03 16:28 UTC
Read the original article Hit count: 206

Filed under:
|

I have a model service and a ModelForm named Service which I use to add and update the service model. The model looks like this:

class Service(models.Model):
    categories = models.ManyToManyField(Category)

The categories field is displayed as a tag with that allows multiple selection. It works well when I'm adding a new record but when I'm updating it, only one service is showing up on the request.POST['categories'] even if I selected multiple categories.

I tried dumping the request object and I can see that the categories is showing something like:

u'categories': [u'3', u'4', u'2']

I tried calling the request._get_post() and it did return only 1 category, hence the request.POST['categories'] returns only 1. Anybody who knows what's happening and how to fix it?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-forms