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, ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.