Create non existing tag with Django-select2
I am using django-select2 to autocomplete a tag field on a model. I would like to let user write any tag in the field, and create it if the tag doesn't exists...
# models.py
class Version(models.Model):
...
tags = models.ManyToManyField(Tag, blank=True)
class VersionTagWidget(s2forms.ModelSelect2TagWidget):
search_fields = [
"nom__icontains",
]
class VersionEditViewForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
...
class Meta:
model = Version
widgets = {
"tags": VersionTagWidget,
}
I can autocomplete value (and select in a dynamic dropdown), but if type in a non-existing (in my example, I entered 'DoesNotExist') value and submit the form, I get :
Exception Value:
Field 'id' expected a number but got 'DoesNotExist'.
I tried a lot of things to solve the pb.... But no clue here...