django m2m .add 1

django m2m .add

p1 = Publication(title='The Python Journal')
a1 = Article(headline='Django lets you build Web apps easily')


# Adding a second time is OK, it will not duplicate the relation:

Here is what the above code is Doing:
1. Creating a Publication object with a title of ‘The Python Journal’.
2. Creating an Article object with a headline of ‘Django lets you build Web apps easily’.
3. Adding the Article object to the Publication object’s article_set.
4. Adding the Publication object to the Article object’s publications.

Similar Posts