django updating m2m field
- by Marconi
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?