model_component
django_spire.core.components.form.model_component
ModelFormComponent
Bases: BaseFormComponent
A :class:BaseFormComponent over a ModelForm, whose model is the
form's own. model_pk=None opens the create flow and a value opens the
edit flow. The row is exposed as the model child, a Glue.model, so
the form lives at component.model.form.
The data for the child comes from two overridable hooks: get_model()
picks the instance (blank or fetched by model_pk by default), and
get_fields() names the exposed fields (the form's own fields unless
fields is set), so scoping and create defaults stay subclass logic.
A relation field's choices are the form's own: its __init__ narrows a
field's queryset, which the form child reads, with the row as
self.instance.
pk is the deprecated name of model_pk, both as a parameter and as
an attribute.
Source code in django_spire/core/components/form/model_component.py
form_base = ModelForm
class-attribute
instance-attribute
form_class = None
class-attribute
fields = None
class-attribute
model_pk = Glue.ComponentParameter(None)
class-attribute
instance-attribute
pk
property
model
Source code in django_spire/core/components/form/model_component.py
get_initial
get_fields
Source code in django_spire/core/components/form/model_component.py
get_model
Source code in django_spire/core/components/form/model_component.py
get_permission_model
Return the form's model, whose permissions Glue.ModelAccessMixin reads.
get_required_access
ADD to create a row and CHANGE to edit one, for Glue.ModelAccessRequiredMixin.