Model helper registry¶
Provides a Registry
type and a RegistryMixin
base class
with three registries, used by other mixin classes.
Helper classes such as forms and views can be registered to the model and later accessed from an instance:
class MyModel(BaseMixin, db.Model):
...
class MyForm(Form):
...
class MyView(ModelView):
...
MyModel.forms.main = MyForm
MyModel.views.main = MyView
When accessed from an instance, the registered form or view will receive the
instance as an obj
parameter:
doc = MyModel()
doc.forms.main() == MyForm(obj=doc)
doc.views.main() == MyView(obj=doc)
The name main
is a recommended default, but an app that has separate forms
for new
and edit
actions could use those names instead.
-
class
coaster.sqlalchemy.registry.
Registry
(param: Optional[str] = None, property: bool = False, cached_property: bool = False)[source]¶ Container for items registered to a model.
-
class
coaster.sqlalchemy.registry.
InstanceRegistry
(registry, obj)[source]¶ Container for accessing registered items from an instance of the model.
Used internally by
Registry
. Returns a partial that will pass in anobj
parameter when called.
-
class
coaster.sqlalchemy.registry.
RegistryMixin
[source]¶ Adds common registries to a model.
Included:
forms
registry, for WTForms formsviews
registry for view classes and helper functionsfeatures
registry for feature availability test functions.
The forms registry passes the instance to the registered form as an
obj
keyword parameter. The other registries pass it as the first positional parameter.