Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

'AttributeError' when runserver restart #13

Open
wuxumjy opened this Issue · 4 comments

4 participants

@wuxumjy

hi:
model/epo.py:
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):
            db.session.add(self)
            db.session.commit()

    def delete_from_db(self):
            db.session.delete(self)
            db.session.commit()

views/epo.py:

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)
else:
art = Epo.query.all()
else:
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'".

@scarletsky

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

@wuxumjy

thanks a lot

@huxuan

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.

@nextcoder

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 referenced this issue from a commit in dhamaniasad/Flask-WhooshAlchemy
@dhamaniasad dhamaniasad Update README.rst
Modified quickstart according to gyllstromk#13
cf47510
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.