I working on a project where I need to add two dependant dropdowns for that I tried to use Django-smart-selects but I having an issue. Here's what I did
Here is my models
class District(models.Model):
name = models.CharField(max_length=100, default=None)
created_at = models.DateField(default=django.utils.timezone.now)
class Meta:
managed = True
db_table = 'District'
def __str__(self):
return self.name
class PoliceStation(models.Model):
name = models.CharField(max_length=100, default=None)
district = models.ForeignKey(
District, on_delete=models.CASCADE, max_length=100)
created_at = models.DateField(default=django.utils.timezone.now)
class Meta:
managed = True
db_table = 'PoliceStation'
def __str__(self):
return self.name
class NewsAndUpdates(models.Model):
title = models.CharField(max_length=250)
description = HTMLField()
category = models.ForeignKey(
Category, on_delete=models.CASCADE, max_length=100)
district = models.ForeignKey(
District, on_delete=models.CASCADE)
policeStation = ChainedForeignKey(
PoliceStation,
chained_field="district",
chained_model_field="district",
show_all=False,
auto_choose=True,
on_delete=models.CASCADE)
class Meta:
managed = True
db_table = 'NewsAndUpdates'
This is my urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('chaining/', include('smart_selects.urls')),
]
Here is my installed apps
INSTALLED_APPS = [
....
'smart_selects',
]
In setting.py
I used this as it was suggested when I was searching about the issue
USE_DJANGO_JQUERY = True
This is my admin.py
class NewsAndUpdatesAdmin(admin.ModelAdmin):
list_display = ('title', 'category', 'created_at',
'is_published', 'is_draft')
admin.site.register(NewsAndUpdates, NewsAndUpdatesAdmin)
But I am getting issue which is
Reverse for 'chained_filter' not found. 'chained_filter' is not a valid view function or pattern name
Using Django version 3.1