I followed all smart selects documentation and its still not working it shows an empty dropdown list
INSTALLED_APPS = [
....
'smart_selects'
....
]
Project urls.py
urlpatterns = [
....
path('chaining/', include('smart_selects.urls')),
....
]
models.py
from django.contrib.auth.models import AbstractUser
from smart_selects.db_fields import ChainedForeignKey
class CitiesCity(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=200)
slug = models.CharField(max_length=255, blank=True, null=True)
name_std = models.CharField(max_length=200)
# location = models.GeometryField()
population = models.IntegerField()
elevation = models.IntegerField(blank=True, null=True)
kind = models.CharField(max_length=10)
timezone = models.CharField(max_length=40)
country = models.ForeignKey('CitiesCountry', models.DO_NOTHING)
region = models.ForeignKey('CitiesRegion', models.DO_NOTHING, blank=True, null=True)
subregion = models.ForeignKey('CitiesSubregion', models.DO_NOTHING, blank=True, null=True)
def __str__(self):
return self.name
class Meta:
managed = False
db_table = 'cities_city'
unique_together = (('country', 'region', 'subregion', 'id', 'name'),)
class CitiesCountry(models.Model):
id = models.BigAutoField(primary_key=True)
name = models.CharField(max_length=200)
slug = models.CharField(max_length=255, blank=True, null=True)
code = models.CharField(unique=True, max_length=2)
code3 = models.CharField(unique=True, max_length=3)
population = models.IntegerField()
area = models.IntegerField(blank=True, null=True)
currency = models.CharField(max_length=3, blank=True, null=True)
currency_name = models.CharField(max_length=50, blank=True, null=True)
language_codes = models.CharField(max_length=250, blank=True, null=True)
phone = models.CharField(max_length=20)
tld = models.CharField(max_length=5)
capital = models.CharField(max_length=100)
continent = models.ForeignKey(CitiesContinent, models.DO_NOTHING, blank=True, null=True)
currency_symbol = models.CharField(max_length=31, blank=True, null=True)
postal_code_format = models.CharField(max_length=127)
postal_code_regex = models.CharField(max_length=255)
def __str__(self):
return self.name
class Meta:
managed = False
db_table = 'cities_country'
class NewUser(AbstractUser):
uuid = models.UUIDField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
mobile = PhoneNumberField(region="EG")
street= models.CharField(max_length=200, null=True, blank=True)
Building= models.CharField(max_length=200, null=True, blank=True)
Floor= models.IntegerField(null=True, blank=True)
Flat= models.IntegerField(null=True, blank=True)
Landmark= models.TextField(null=True, blank=True)
country = models.ForeignKey(CitiesCountry, on_delete=models.CASCADE, null=True, blank=True)
city = models.ForeignKey(CitiesCity, on_delete=models.CASCADE, blank=True, null=True)
district = models.ForeignKey(CitiesDistrict, on_delete=models.CASCADE, blank=True, null=True)
categories = models.ForeignKey(category, on_delete=models.CASCADE, blank=True, null=True)
city = ChainedForeignKey(CitiesCity, chained_field ='country', chained_model_field='name',
show_all=False, auto_choose=True, sort=True, null=True, blank=True)
forms.py
from django.contrib.auth.forms import UserCreationForm
from django import forms
from .models import NewUser
class CustomUserCreationForm(UserCreationForm):
class Meta:
model = NewUser
fields = ['first_name', 'last_name', 'email', 'username', 'password1', 'password2', 'mobile', 'street', 'Building', 'Floor', 'Flat', 'Landmark', 'country', 'city']
def __init__(self, *args, **kwargs):
super(CustomUserCreationForm, self).__init__(*args, **kwargs)
for name, field in self.fields.items():
field.widget.attrs.update({'class': 'textbox'})