Empty Dropdown Using ModelSelect2Widget
celine-setyawan opened this issue · comments
Hello, thank you for the opensource, this is my first time using django-select2.
I don't know why my dropdown won't show anything. This is the frontend. I want those 4 fields chained. But they dont even show any data.
'
Seems like I have similar problem like this issue. I've tried the solution but it doesn't work for me. If I remove the widgets=ModelSelect2Widget, my dropdown is populated with data from the DB, so I guess the problem lies with the ModelSelect2Widget. I use django-select2==7.4.2 and django==3.0.7
This is my forms.py
class FormSekolah(ModelForm):
provinsi = ModelChoiceField(
queryset=Provinsi.objects.all(),
widget=ModelSelect2Widget(
attrs={
'class': 'form-control form-control-sm',
'data-placeholder': '-- Pilih Provinsi --',
'data-minimum-input-length': 0
},
model=Provinsi,
search_fields=['nama__icontains'],
dependent_fields={'kokab': 'cities'}
)
)
class Meta:
model = Sekolah
fields = [
# other field,
'provinsi',
]
This is my models.py
class Provinsi(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
nama = models.CharField(max_length=50)
negara = models.ForeignKey(Negara, on_delete=models.CASCADE, related_name="provinces")
def __str__(self):
return self.nama
Do I need to do something with my views.py (beside create and save forms and render to the html) or even create my own .js ?
Thanks before.
This repo is no longer maintained. Please resubmit your question at https://github.com/codingjoe/django-select2/issues/new
Thanks for the notification @codingjoe