Saving and modifying tags on posts

We have covered how to save and modify tags on our entries. One of the most common approaches to managing tags is to use a comma-separated text input, so we might list the tags as Python, Flask, Web-development. With WTForms this seems pretty straightforward, since we would just use a StringField. The fact that we are dealing with a database relationship, though, means that at some point we need to do some processing to convert between Tag models and a comma-separated string.

While there are many ways we could accomplish this, we will implement a custom field class TagField, which will encapsulate all the logic for translating between comma-separated tag names and Tag model instances.

Tip

Another option would be ...

Get Learning Flask Framework 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.