code: def create_tag(tag_name, kind='z'):
          '''
          Create tag record by tag_name
          '''
          cur_recs = TabTag.select().where(
              (TabTag.name == tag_name) &
              (TabTag.kind == kind)
          )
          if cur_recs.count():
              uid = cur_recs.get().uid
  
              # TabTag.delete().where(
              #     (TabTag.name == tag_name) &
              #     (TabTag.kind == kind)
              # ).execute()
          else:
              uid = tools.get_uu4d_v2()  # Label with the ID of v2.
              while TabTag.select().where(TabTag.uid == uid).count() > 0:
                  uid = tools.get_uu4d_v2()
  
              TabTag.create(
                  uid=uid,
                  slug=uid,
                  name=tag_name,
                  order=1,
                  count=0,
                  kind='z',
                  tmpl=9,
                  pid='zzzz',
              )
          return uif create_tag(tag_name, kind='z'):
          '''
          Create tag record by tag_name
          '''
          cur_recs = TabTag.select().where(
              (TabTag.name == tag_name) &
              (TabTag.kind == kind)
          )
          if cur_recs.count():
              uid = cur_recs.get().uid
  
              # TabTag.delete().where(
              #     (TabTag.name == tag_name) &
              #     (TabTag.kind == kind)
              # ).execute()
          else:
              uid = tools.get_uu4d_v2()  # Label with the ID of v2.
              while TabTag.select().where(TabTag.uid == uid).count() > 0:
                  uid = tools.get_uu4d_v2()
  
              TabTag.create(
                  uid=uid,
                  slug=uid,
                  name=tag_name,
                  order=1,
                  count=0,
                  kind='z',
                  tmpl=9,
                  pid='zzzz',
              )
          return uid
docs: Create tag record by tag_name