如何在mongoengine中链接查询范围

时间:2016-11-24 09:51:29

标签: python scope mongoengine chaining

我已经定义了查询范围,并希望在访问时链接它们,但它会抛出错误AttributeError: 'QuerySet' object has no attribute 'active'

这是我的代码:

class User(Document):
    name = StringField(max_length=120, default=None)
    is_paid = BooleanField(default=True, required=True)
    is_active = BooleanField(default=True, required=True)
    created_at = DateTimeField(default=datetime.now(), required=True)

    meta = {
      'collection': 'users'
    }

    @queryset_manager
    def paid(doc_cls, queryset):
      return queryset.filter(is_paid=True)

    @queryset_manager
    def active(doc_cls, queryset):
        return queryset.filter(is_active=True)

现在我试图像这样链接范围:

users = User.paid().active()
print(users)

帮我解决这个问题: - )

0 个答案:

没有答案