FlaskWhooshee错误“WhoosheeQuery”对象没有属性“\u join\u entities”

2024-05-14 12:03:26 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我基于模型的炼金术

@whooshee.register_model('title','content')
class PostModel(db.Model):
    __tablename__ = 'post'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    title = db.Column(db.String(200),nullable=False)
    content = db.Column(db.Text,nullable=False)
    create_time = db.Column(db.DateTime,default=datetime.now)
    read_count = db.Column(db.Integer,default=0)
    board_id = db.Column(db.Integer,db.ForeignKey("board.id"))
    author_id = db.Column(db.String(100),db.ForeignKey("front_user.id"),nullable=False)
@bp.route('/search/')
def index_search():
    q = request.args.get('q','')
    print(q)
    if q == '':
        flash('enter key words','warning')
        return redirect(url_for('front.index'))
    result = PostModel.query.whooshee_search(q).order_by(PostModel.create_time.desc()).all()
    print(result)
    return render_template('front/front_search.html',result=result)

如果self.\u join_实体和isinstance(self.\u join_实体[0],映射器): AttributeError:“WhoosheeQuery”对象没有属性“\u连接\u实体”

你能告诉我怎么解决这个问题吗


Tags: key实体idfalsedbsearchtitlecolumn
2条回答

这可能不是最好的解决方案,但由于您只在PostModel上使用whooshee搜索,请在flask_whooshee.py模块中注释掉这一部分

if self._join_entities and isinstance(self._join_entities[0], Mapper):
    # SQLAlchemy >= 0.8.0
    entities.update(set([x.entity for x in self._join_entities]))
else:
    # SQLAlchemy < 0.8.0
    entities.update(set(self._join_entities))
             

在flask_whooshee.py模块中注释掉这一部分。它对我有用

if self._join_entities and isinstance(self._join_entities[0], Mapper):
# SQLAlchemy >= 0.8.0
entities.update(set([x.entity for x in self._join_entities]))

其他: #炼金术<;0.8.0 实体更新(集合(自连接实体))

相关问题 更多 >

    热门问题