def addTags(scopeitem, tags): from app.models import Tag for tag in tags: if tag.strip() == "": # If the tag is an empty string then don't use it continue tag_obj = Tag.create_if_none(tag) scopeitem.addTag(tag_obj)