views:

75

answers:

1

I can't find it anywhere, so your help will be nice for me :) Here is that field:

categories = models.ManyToManyField(fragmentCategory)

FragmentCategory:

class fragmentCategory(models.Model):

        CATEGORY_CHOICES = (
                     ('val1', 'value1'),
                     ('val2', 'value2'),
                     ('val3', 'value3'),
                        )

        name = models.CharField(max_length=20, choices=CATEGORY_CHOICES)

Here form to send:

<input type="checkbox" name="val1" />
<input type="checkbox" name="val2" />
<input type="checkbox" name="val3" />


I tried smth like this:

categories = fragmentCategory.objects.get(id=1),

Or:

categories = [1,2]
+2  A: 

There's a whole page of the Django documentation devoted to this, well indexed from the contents page.

As that page states, you need to do:

my_obj.categories.add(fragmentCategory.objects.get(id=1))

or

my_obj.categories.create(name='val1')
Daniel Roseman