O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

25.3.2 Automatically Assigning Tag Objects to Post Instances

In this section, we implement a signal handler to assign Tag objects to Post instances whenever a Post and Startup are related.

A Post may be related to a Startup in various ways, as shown in Example 25.9.

Example 25.9: Python Code

post_object.startups.add(startup_object1, startup_object2) startup_object.blog_posts.add(post_object1, post_object2)

Even though a many-to-many relationship is symmetric (if you are someone’s friend, then they are also your friend), Django defines the first relation as the forward relation, while the second is the reverse relation. Django uses this definition in our signal handler, too.

To start, we need to import our tools, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required