发现了一个Bug:外键的外键不会进行is_valid验证
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
评论 (0)