发现了一个Bug:外键的外键不会进行is_valid验证
代码语言:javascript复制class ValidQueryset(models.QuerySet):
def filter(self, *args, **kwargs):
is_valid = kwargs.pop('is_valid', True)
if isinstance(is_valid, bool):
kwargs['is_valid'] = is_valid
return super().filter(*args, **kwargs)
class BaseManage(models.Manager):
_queryset_class = ValidQueryset
class BaseModel(models.Model):
is_valid = models.BooleanField(default=True, verbose_name='数据有效/无效')
objects = BaseManage()
class Meta:
abstract = True