我在一个项目中工作,我需要添加两个相关的下拉列表,我尝试使用 Django-smart-selects 但我遇到了问题。这就是我所做的
这是我的模型
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'
这是我的 urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('chaining/', include('smart_selects.urls')),
]
这是我安装的应用程序
INSTALLED_APPS = [
....
'smart_selects',
]
在setting.py
我搜索问题时,我按照建议使用了这个
USE_DJANGO_JQUERY = True
这是我的 admin.py
class NewsAndUpdatesAdmin(admin.ModelAdmin):
list_display = ('title', 'category', 'created_at',
'is_published', 'is_draft')
admin.site.register(NewsAndUpdates, NewsAndUpdatesAdmin)
但我遇到的问题是
Reverse for 'chained_filter' not found. 'chained_filter' is not a valid view function or pattern name
使用 Django 3.1 版