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.