from django import forms 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(FormControlBase): _formcontrol_fields = ["component"] component = forms.ModelChoiceField( queryset=Component.objects.all(), required=False ) class SupplierSearchForm(FormControlBase): _formcontrol_fields = ["supplier"] supplier = forms.ModelChoiceField( queryset=Supplier.objects.filter(is_authorized=True), required=False )