from superdjango import ui
from .constants import DATA_TYPE
__all__ = (
"BaseAttributeInlineModelUI",
"BaseAttributeModelUI",
)
# Inlines
[docs]class BaseAttributeInlineModelUI(ui.InlineModelUI):
"""Base inline for including attributes fields."""
detail_options = ui.InlineDetailOptions(
"label",
"data_type",
"raw_default_value",
"sort_order",
"is_required",
"is_enabled"
)
# Models
[docs]class BaseAttributeModelUI(ui.ModelUI):
"""Base UI for an attribute model."""
controls = {
'data_type': ui.controls.ChoiceControl(
on_select=[
ui.OnSelect(
DATA_TYPE.DECIMAL,
target_field=["decimal_places", "max_digits"],
required=True,
visible=True
),
ui.OnSelect(
DATA_TYPE.LIST,
target_field=["choices", "content_type", "limit_choices_to"],
visible=True
),
ui.OnSelect(
DATA_TYPE.VARCHAR,
target_field=["max_length", "min_length"],
required=True,
visible=True
),
]
),
'is_hidden': ui.controls.BooleanControl(align="center", css_icon=True),
'is_enabled': ui.controls.BooleanControl(align="center", css_icon=True),
'is_required': ui.controls.BooleanControl(align="center", css_icon=True),
}
detail_options = ui.DetailOptions(
"label",
"name",
"help_text",
"data_type",
"is_required",
"choices",
"content_type",
"limit_choices_to",
"max_length",
"min_length",
"decimal_places",
"max_digits",
"raw_default_value",
"sort_order",
"is_hidden",
"is_enabled"
)
form_options = ui.ModelFormOptions(
"label",
"name",
"help_text",
"data_type",
"is_required",
"choices",
"content_type",
"limit_choices_to",
"max_length",
"min_length",
"decimal_places",
"max_digits",
"raw_default_value",
"sort_order",
"is_hidden",
"is_enabled"
)
list_options = ui.ListOptions(
"label",
"data_type",
"is_required",
"is_enabled",
"raw_default_value",
filtering=ui.Filtering("data_type", "is_required", "is_enabled")
)