-
Notifications
You must be signed in to change notification settings - Fork 21
Models BaseMixin
Kyle J. Roux edited this page Sep 7, 2015
·
3 revisions
To use the BaseMixin
class, please define DATABASE_URI
in your settings, ie:
DATABASE_URI = 'sqlite:///xxx.db'
This does not work with flask-sqlalchemy
, please do not use together or you will get errors.
For easy model creation, we have a class we can inherit many useful methods, flask_xxl.basemodels.BaseMixin
. This class has a number of goodies:
- attrs
- session -> defined on the Baseclass so this is shared by all model instances
- engine -> defined on baseclass so this is also shared
- metadata -> also shared
- query -> defined on model class, so each model class has individual query
- methods
- save -> instance level save method, returns instance so method chaining is possible
- ie: model.save().get_all()
- delete -> instance level delete method
- get -> alias to model.query(model).filter()
- get_all -> alias to model.query(model).all()
- save -> instance level save method, returns instance so method chaining is possible
also defines your models __tablename__
using the inflection
library to generate the plural of your class name, and provides an auto generated id
column using sqlalchemy.ext.declarative.declarred_attr
Jstacoder [email protected]
Examples