| 1 |
from typing import Any |
| 2 |
|
| 3 |
from django import forms |
| 4 |
from django.contrib.admin.widgets import AdminRadioSelect |
| 5 |
from django.utils.translation import gettext_lazy as _ |
| 6 |
|
| 7 |
|
| 8 |
class PolymorphicModelChoiceForm(forms.Form): |
| 9 |
""" |
| 10 |
The default form for the ``add_type_form``. Can be overwritten and replaced. |
| 11 |
""" |
| 12 |
|
| 13 |
#: Define the label for the radiofield |
| 14 |
type_label = _("Type") |
| 15 |
|
| 16 |
ct_id = forms.ChoiceField( |
| 17 |
label=type_label, widget=AdminRadioSelect(attrs={"class": "radiolist"}) |
| 18 |
) |
| 19 |
|
| 20 |
def __init__(self, *args: Any, **kwargs: Any) -> None: |
| 21 |
# Allow to easily redefine the label (a commonly expected usecase) |
| 22 |
super().__init__(*args, **kwargs) |
| 23 |
self.fields["ct_id"].label = self.type_label |