Hello I was wondering how you could update a Select2TagWidget inside Django?
Right now my forms.py looks like this:
### REPRESENTATIVE POSTALRANGES ###
class UpdatePostalRepresentativeForm(ModelForm):
class Meta:
model = PostalRepresentative
fields = '__all__'
widgets = {
'representative' : s2forms.ModelSelect2Widget(
model=PostalRepresentative,
queryset= User.objects.filter(permission = "REPRESENTATIVE"),
attrs={'data-placeholder':_("Representative"), 'data-minimum-input-length': 1},
search_fields = ['first_name__icontains']
),
'postalCodes' : s2forms.Select2TagWidget(attrs=None, choices=())
}
My models.py:
class Customers(models.Model):
PERIODIC_VISIT_NOT = "NOT"
PERIODIC_VISIT_2MONTHS = "2 MONTHS"
PERIODIC_VISIT_4MONTHS = "4 MONTHS"
PERIODIC_VISIT_DEFAULT = "6 MONTHS"
PERIODIC_VISIT_12MONTHS = "12 MONTHS"
PERIODIC_VISIT_18MONTHS = "18 MONTHS"
PERIODIC_VISIT = (
(PERIODIC_VISIT_NOT, "NOT"),
(PERIODIC_VISIT_2MONTHS, "2 Months"),
(PERIODIC_VISIT_4MONTHS, "4 Months"),
(PERIODIC_VISIT_DEFAULT, "6 Months"),
(PERIODIC_VISIT_12MONTHS, "12 Months"),
(PERIODIC_VISIT_18MONTHS, "18 Months"),
)
active = models.BooleanField(default=False)
reasonInactive = models.CharField(max_length=250, default="", blank=True, null=True)
vetoId = models.IntegerField(default=0, blank=True, null=True)
companyName = models.CharField(max_length=250, default="", blank=True, null=True)
contactPerson = models.CharField(max_length=250, default="", blank=True, null = True)
telephoneNumber = models.IntegerField(default=0, blank=True, null=True)
smartphoneNumber = models.IntegerField(default=0, blank=True, null = True)
email = models.EmailField(default="", blank=True, null=True)
website = models.CharField(max_length=250, default="", blank=True, null=True)
specialities = ArrayField(models.CharField(max_length=250, default= False, blank = True, null = True), blank=True, null=True)
periodicVisit = models.CharField(max_length=250, choices=PERIODIC_VISIT, default="", blank=True, null = True)
# LOCATION #
street = models.CharField(max_length=250, default="", blank=True, null=True)
housenumber = models.CharField(max_length=250, default="", blank=True, null=True)
city = models.CharField(max_length=250, default="", blank=True, null=True)
postalcode = models.IntegerField(default="", blank=True, null=True)
note = models.CharField(max_length=250, default="", blank=True, null=True)
address = models.ForeignKey(Address, on_delete=models.CASCADE, related_name="referentie_adres", blank=True, null = True)
def __str__(self) -> str:
return self.contactPerson
The result of this is that the data doesn’t get loaded in when trying to update it. So it’s just an empty input box and I can’t insert anything either.
Picture:
Any solution to fix this issue? Or is updating a select2 tag field just not possible?