diff options
Diffstat (limited to 'procurement/forms.py')
-rw-r--r-- | procurement/forms.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/procurement/forms.py b/procurement/forms.py index 4e8b0aa..0aeca9b 100644 --- a/procurement/forms.py +++ b/procurement/forms.py @@ -1,14 +1,24 @@ from django import forms -from procurement.models import Component +from procurement.models import Component, Supplier +class FormControlBase(forms.Form): + _formcontrol_fields = [] + def __init__(self, *args, **kwargs): + super(FormControlBase, self).__init__(*args, **kwargs) + for fieldname in self._formcontrol_fields: + self.fields[fieldname].widget.attrs.update({"class": "form-control"}) -class ComponentSearchForm(forms.Form): +class ComponentSearchForm(FormControlBase): + _formcontrol_fields = ["component"] component = forms.ModelChoiceField( queryset=Component.objects.all(), required=False ) - def __init__(self, *args, **kwargs): - super(ComponentSearchForm, self).__init__(*args, **kwargs) - self.fields['component'].widget.attrs.update({"class": "form-control"}) +class SupplierSearchForm(FormControlBase): + _formcontrol_fields = ["supplier"] + supplier = forms.ModelChoiceField( + queryset=Supplier.objects.filter(is_authorized=True), + required=False + ) |