django - how to add data into ManyToManyField? -
I can not find it anywhere, so your help will be good for me :) Here's the field:
categories = models.ManyToManyField (fragmentCategory)
fragment category:
category category (models.Model): CATEGORY_CHOICES = ('Val1', 'value1'), ('val2', 'value2'), ('val3', 'value3'), name = model.ccarfield (max_length = 20, options = CATEGORY_CHOICES)
Here's a type of sending:
& Lt; Input type = "checkbox" name = "val2" /> & Lt; Input type = "checkbox" name = "val3" />
I tried to do something like this:
categories = fragment category.objects.get (id = 1),
or:
categories = [1,2]
A complete page of the Django documentary is well-indexed from the content page.
According to that page, you have to:
my_obj .categories.add (fragmentCategory.objects.get (id = 1))
or
my_obj.categories.create (name = 'val1')
Comments
Post a Comment