code: def get_id_by_name(tag_name, kind='z'):
          '''
          Get ID by tag_name of the label.
          '''
          recs = TabTag.select().where(
              (TabTag.name == tag_name) & (TabTag.kind == kind)
          )
          logger.info('tag count of {0}: {1} '.format(tag_name, recs.count()))
          # the_id = ''
          if recs.count() == 1:
              the_id = recs.get().uid
          elif recs.count() > 1:
              rec0 = None
              for rec in recs:
                  # Only keep one.
                  if rec0:
                      TabPost2Tag.delete().where(TabPost2Tag.tag_id == rec.uid).execute()
                      TabTag.delete().where(TabTag.uid == rec.uid).execute()
                  else:
                      rec0 = rec
  
              the_id = rec0.uid
          else:
              the_id = MLabel.create_tag(tag_name)
          return the_if get_id_by_name(tag_name, kind='z'):
          '''
          Get ID by tag_name of the label.
          '''
          recs = TabTag.select().where(
              (TabTag.name == tag_name) & (TabTag.kind == kind)
          )
          logger.info('tag count of {0}: {1} '.format(tag_name, recs.count()))
          # the_id = ''
          if recs.count() == 1:
              the_id = recs.get().uid
          elif recs.count() > 1:
              rec0 = None
              for rec in recs:
                  # Only keep one.
                  if rec0:
                      TabPost2Tag.delete().where(TabPost2Tag.tag_id == rec.uid).execute()
                      TabTag.delete().where(TabTag.uid == rec.uid).execute()
                  else:
                      rec0 = rec
  
              the_id = rec0.uid
          else:
              the_id = MLabel.create_tag(tag_name)
          return the_id
docs: Get ID by tag_name of the label.