Mixin classes for helping build forms with WTForms populating SQLAlchemy objects.
Note
The following packages must be installed:
Bases: object
Base Mixin for Creating or Updating a object with SQLAlchemy.
Warning
This mixin cannot be used on it’s own and should be used inconjunction with others, such as ModelFormMixin.
Overrides success_callback creating new model objects. This method is called on successful form validations. It first obtains the current db session and the instantiated form. A blank object is obtained from the model and then populated with the form data.
session = self.get_session()
form = self.get_form()
obj = self.get_object()
form.populate_obj(obj)
session.add(obj)
session.commit()
Returns: | Redirects request to somewhere else |
---|---|
Return type: | werkzeug.wrappers.Response |
Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin, flask_velox.mixins.forms.FormMixin
Handles creating objects after form validation has completed and was successful.
Flash created message to user.
Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin, flask_velox.mixins.forms.FormMixin
Handels updating a single existing object after form validation has completed and was successful.
Flash updated message to user.
Overrides form instantiation so object instance can be passed to the form.
obj = self.get_object()
return super(UpdateModelFormMixin, self).instantiate_form(
obj=obj,
**kwargs)
See also
Returns: | Instantiated form |
---|---|
Return type: | object |
Bases: flask_velox.mixins.sqla.object.SingleObjectMixin, flask_velox.mixins.sqla.forms.BaseCreateUpdateMixin, flask_velox.mixins.forms.MultiFormMixin
Mixin for building mutli forms with a single SQAlachemy object
Example
1 2 3 4 5 6 7 8 9 10 | from flask.ext.velox.mixins.sqla.forms import ModelFormMixin
from yourapp.forms import MyForm1, MyForm2
from yourapp.models import MyModel
class MyView(UpdateModelMultiFormMixin):
model = MyModel
forms = [
'Form 1': MyForm1
'Form 2': MyForm2
]
|