from tortoise import fields, models from tortoise.expressions import Q class Taboo(models.Model): name = fields.CharField(max_length = 50, description = '药剂种类') mutex = fields.CharField(max_length = 50, description = '禁忌种类') reason = fields.CharField(max_length = 255, description = '禁忌描述') class Meta: table = 'taboos' table_description = '禁忌表' @classmethod async def conflict(cls, mine, othn): '''是否存在存储禁忌''' mtags = mine.split(',') otags = othn.split(',') for mtag in mtags: for otag in otags: taboo = await Taboo.get_or_none(Q(name=mtag, mutex=otag) | Q(name=otag, mutex=mtag)) if taboo: return True, taboo.reason return False, None