def exists(cls, *args, **kwargs):
terms = None
if len(args) == 1:
if not isinstance(args[0], ClauseElement):
terms = [getattr(cls, cls.PKEY) == args[0]]
if not terms:
terms = list(args) + \
[getattr(cls, k) == v for k, v in kwargs.items()]
res = db.query(getattr(cls, cls.PKEY)).filter(*terms).limit(1).first()
if res:
return res.id
return False
评论列表
文章目录