O'Reilly logo

Learning Flask Framework by Charles Leifer, Matt Copperwaite

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

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

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