0

我有 2 个课程(我正在使用 Flask-mongoengine):

class ArticleCategory(db.Document):
    name = db.StringField(verbose_name='Title', required=True, unique=True)
    desc = db.StringField(verbose_name='Slug', required=True)

class Article(CreateUpdateMixin, DeletedMixin, db.Document):
    title = db.StringField(verbose_name='Title', required=True)
    slug = db.StringField(verbose_name='Slug', required=True, unique=True)
    content = db.StringField(verbose_name='Content', required=True)
    #Many-to-many relation
    categories = db.ListField(db.ReferenceField(ArticleCategory),
                              verbose_name='Category', required=True)

    def __unicode__(self):
        return self.title

现在我想按特定类别(或类别名称)获取所有文章。__eq我在 mongoengine 查询帮助中找不到运算符。

操作员Article.objects(categories__in('some_category'))失败。

4

1 回答 1

1

您有错误的查询,请参阅文档http://mongoengine.readthedocs.io/en/latest/guide/querying.html#query-operators

Article.objects(categories__in=['ARTICLE_CATEGORY_ID'])
于 2013-09-09T06:26:24.893 回答