Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'AttributeError' when runserver restart #13

Closed
wuxumjy opened this issue Mar 11, 2013 · 4 comments
Closed

'AttributeError' when runserver restart #13

wuxumjy opened this issue Mar 11, 2013 · 4 comments
Labels

Comments

@wuxumjy
Copy link

wuxumjy commented Mar 11, 2013

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
Copy link

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

@wuxumjy
Copy link
Author

wuxumjy commented Apr 7, 2013

thanks a lot

@huxuan
Copy link
Contributor

huxuan commented Feb 14, 2014

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.

@ncmonger
Copy link

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 added a commit to dhamaniasad/Flask-WhooshAlchemy that referenced this issue Nov 30, 2014
Modified quickstart according to gyllstromk#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants