# How to Use Forms, Widgets, and the Admin Registry model fields produce appropriate form fields by default, but you can also use them directly or swap in context-aware and hierarchical variants. ## Form Fields ### RegistryFormField A `ChoiceField` that presents registry implementations as choices and returns the selected class on clean. ```python from django_stratagem import RegistryFormField class MyForm(forms.Form): strategy = RegistryFormField(registry=NotificationRegistry) ``` ### RegistryMultipleChoiceFormField A `TypedMultipleChoiceField` for selecting multiple implementations. ```python from django_stratagem import RegistryMultipleChoiceFormField class MyForm(forms.Form): strategies = RegistryMultipleChoiceFormField(registry=NotificationRegistry) ``` ### ContextAwareRegistryFormField Limits the choices shown based on the current user's permissions, feature flags, or other runtime state (used with `ConditionalInterface`). ```python from django_stratagem import ContextAwareRegistryFormField class MyForm(forms.Form): strategy = ContextAwareRegistryFormField( registry=NotificationRegistry, context={"user": request.user, "request": request}, ) ``` Call `field.set_context(new_context)` to update the context and refresh choices. ### HierarchicalRegistryFormField Shows only child options that are valid for the selected parent. ```python from django_stratagem import HierarchicalRegistryFormField class MyForm(forms.Form): category = RegistryFormField(registry=CategoryRegistry) subcategory = HierarchicalRegistryFormField( registry=SubcategoryRegistry, parent_field="category", ) ``` Call `field.set_parent_value(value)` to update the parent and refresh choices. ## Form Mixins ### RegistryContextMixin Mixin for forms that need to pass context to `ContextAwareRegistryFormField` fields. ```python from django_stratagem import RegistryContextMixin class MyForm(RegistryContextMixin, forms.Form): strategy = ContextAwareRegistryFormField(registry=NotificationRegistry) # Usage: form = MyForm(registry_context={"user": request.user}) ``` ### HierarchicalFormMixin Mixin for forms with hierarchical registry fields. Automatically sets up parent-child relationships and validates them on clean. ```python from django_stratagem import HierarchicalFormMixin class MyForm(HierarchicalFormMixin, forms.ModelForm): class Meta: model = MyModel fields = ["category", "subcategory"] ``` ## Widgets ### RegistryWidget Enhanced `Select` widget that adds `title` (description), `data-description`, `data-icon`, and `data-priority` attributes to each `