def __init__(self, *args, **kwargs):
        """
        Automaticaly generate form fields with dynamic names based on the filtering field name
        """
        self.field_name = kwargs.pop('field_name', 'date')
        self.title = kwargs.pop('title', 'Date').title()
        super(DateRangeForm, self).__init__(*args, **kwargs)

        self.fields['%s_start' % self.field_name] = forms.DateField(
            widget=SuitDateWidget(attrs={'placeholder': self.title, 'style': 'width=330px;'}), label=pgettext('date', 'From'), required=False)
        self.fields['%s_end' % self.field_name] = forms.DateField(
            widget=SuitDateWidget(attrs={'placeholder': self.title}), label=pgettext('date', 'To'), required=False)
def __init__ ( self , * args , ** kwargs ) : self . field_name = kwargs . pop ( 'field_name' , 'date' ) self . title = kwargs . pop ( 'title' , 'Date' ) . title ( ) super ( DateRangeForm , self ) . __init__ ( * args , ** kwargs ) self . fields [ '%s_start' % self . field_name ] = forms . DateField ( widget = SuitDateWidget ( attrs = { 'placeholder' : self . title , 'style' : 'width=330px;' } ) , label = pgettext ( 'date' , 'From' ) , required = False ) self . fields [ '%s_end' % self . field_name ] = forms . DateField ( widget = SuitDateWidget ( attrs = { 'placeholder' : self . title } ) , label = pgettext ( 'date' , 'To' ) , required = False )
Automaticaly generate form fields with dynamic names based on the filtering field name