Django 2 How to reassign the widgets form fields, but the fields for different widgets?

There is a class in models.py
class BarberCustomer(models.Model):
"'A client name, service and time"'
service = models.ForeignKey(BarberService, on_delete = models.SET_NULL, verbose_name='Name of service',blank=True, null=True, related_name='service_customer') #related_name need to display then comments on the detail page
name_barber_customer = models.CharField('Your name', max_length=50)
telephone_number_cust_barber = models.CharField('Your phone number', max_length=13)
date_termin = models.DateTimeField('date and time')


There is a form in forms.py

class BarberCustomerForm(forms.ModelForm):
class Meta:
 model = BarberCustomer
 fields = '__all__'

#reassigned the widget class for easy date selection and time
def __init__(self, *args, **kwargs):
 super().__init__(*args, **kwargs)
 self.fields['date_termin'].widget.attrs.update({'class':'daterangepicker-custom'})


If I set the widget class to other fields such as service and write the code below the method to reassign the widget calendar, the website calendar is not working, and only applies the last class and only for field service. Accordingly, if you swap them, the calendar works, and the service is displayed as default without a new widget class.

How to manage form so you can assign different widgets for the fields in one form?
April 19th 20 at 12:35
0 answer

Find more questions by tags Django