'AttributeError' when runserver restart #13

wuxumjy opened this Issue Mar 11, 2013 · 4 comments

4 participants


from cscsearch.extensions import db
import flask.ext.whooshalchemy
import datetime

class Epo(db.Model):
tablename = 'epo'
searchable = ['title', 'doc']

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200))
    doc = db.Column(db.Text())
    tag = db.Column(db.String(120))
    date = db.Column(db.DateTime(),default = datetime.datetime.now())

    def __repr__(self):
            return '{0}(title={1})'.format(self.__class__.__name__, self.title)
            #return self.title,self.doc

    def __unicode__(self):
            return self.title

    def store_to_db(self):

    def delete_from_db(self):


from cscsearch.models import Anonymous, User, LoginUser, Log, Epo

epo = Blueprint("epo", name)

@epo.route('/', methods=['GET','POST'])
def index():
if request.method == 'POST':
se = request.form['se']
if se:
art = Epo.query.whoosh_search(se)
art = Epo.query.all()
art = Epo.query.all()

return render_template("epodoc.html",art=art)

when add some new content, it will work well. But when Flask runserver restart, it will show "AttributeError: 'BaseQuery' object has no attribute 'whoosh_search'".


You can add the following statement at the end of models.py
flask.ext.whooshalchemy.whoosh_index(app, Epo)


thanks a lot


Seems the doc is a little misleading as there are no metion about whoosh_index manually in models. Maybe it would be better to clarify it in doc.


For those who are using this within the FlaskBB framework,
the app configuration is in the manage.py:

app = create_app(Config)
app.config['WHOOSH_BASE'] = '/pathto/whoosh/base'
fwa.whoosh_index(app, Epo) <---- this line needs to be repeated for all the Models that are indexed by Whoosh

@dhamaniasad dhamaniasad added a commit to dhamaniasad/Flask-WhooshAlchemy that referenced this issue Nov 30, 2014
@dhamaniasad dhamaniasad Update README.rst
Modified quickstart according to gyllstromk#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment