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 anobjparameter when called.
-
class
coaster.sqlalchemy.registry.RegistryMixin[source]¶ Adds common registries to a model.
Included:
formsregistry, for WTForms formsviewsregistry for view classes and helper functionsfeaturesregistry for feature availability test functions.
The forms registry passes the instance to the registered form as an
objkeyword parameter. The other registries pass it as the first positional parameter.