code: def favstar(self, class_name, obj_id, action):
          
          session = db.session()
          FavStar = models.FavStar  # noqa
          count = 0
          favs = session.query(FavStar).filter_by(
              class_name=class_name, obj_id=obj_id,
              user_id=g.user.get_id()).all()
          if action == 'select':
              if not favs:
                  session.add(
                      FavStar(
                          class_name=class_name,
                          obj_id=obj_id,
                          user_id=g.user.get_id(),
                          dttm=datetime.now(),
                      ),
                  )
              count = 1
          elif action == 'unselect':
              for fav in favs:
                  session.delete(fav)
          else:
              count = len(favs)
          session.commit()
          return json_success(json.dumps({'count': count}))
docs: Toggle favorite stars on Slices and Dashboard