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")
More Related Contents:
- Extending the User model with custom fields in Django
- What’s the difference between django OneToOneField and ForeignKey?
- How to set a Django model field’s default value to a function call / callable (e.g., a date relative to the time of model object creation)
- Django: Get model from string?
- Django: Get list of model fields?
- How to filter empty or NULL names in a QuerySet?
- How do I get Django Admin to delete files when I remove an object from the database/model?
- How to view corresponding SQL query of the Django ORM’s queryset?
- In a django model custom save() method, how should you identify a new object?
- Unique fields that allow nulls in Django
- Using a UUID as a primary key in Django models (generic relations impact)
- Django ManyToMany filter()
- Tying in to Django Admin’s Model History
- ImageField overwrite image file with same name
- django dynamically filtering with q objects
- How to limit queryset/the records to view in Django admin site?
- How to assign currently logged in user as default value for a model field?
- Django: implementing JOIN using Django ORM?
- Django – Simple custom template tag example
- Django user profile
- How can I restrict Django’s GenericForeignKey to a list of models?
- Django ManyToMany model validation
- how to show datepicker calendar on datefield
- Django – Overriding the Model.create() method?
- Multiple images per Model
- Can Django automatically create a related one-to-one model?
- Limit number of model instances to be created – django
- django most efficient way to count same field values in a query
- Sharing models between Django apps
- Django: dynamic database file