Django Smart Select链式下拉菜单不起作用

时间:2019-10-14 14:57:12

标签: django django-smart-selects

我正在尝试学习django smart select,但似乎无法使我的连锁下拉菜单正常工作。

我的模特是

from django.db import models
from smart_selects.db_fields import ChainedForeignKey


class Continent(models.Model):
    name = models.CharField(max_length=255)


class Country(models.Model):
    continent = models.ForeignKey(Continent, on_delete=models.CASCADE)
    name = models.CharField(max_length=255)


class Location(models.Model):
    continent = models.ForeignKey(Continent, on_delete=models.CASCADE)
    country = ChainedForeignKey(
        Country,
        chained_field="continent",
        chained_model_field="continent",
        show_all=False,
        auto_choose=True,
        sort=True)
    city = models.CharField(max_length=50)
    street = models.CharField(max_length=100)

在我的管理页面中

from django.contrib import admin
from .models import Location, Continent, Country


class LocationAdmin(admin.ModelAdmin):
    pass


admin.site.register(Location, LocationAdmin)


class ContinentAdmin(admin.ModelAdmin):
    pass


class CountryAdmin(admin.ModelAdmin):
    pass


admin.site.register(Continent, ContinentAdmin)


admin.site.register(Country, CountryAdmin)

在urls.py中,我做了

urlpatterns = [
    path('admin/', admin.site.urls),
    url(r'^chaining/', include('smart_selects.urls')),
]

在settings.py中,我做了

INSTALLED_APPS = [
    'smart_selects',
    'location.apps.LocationConfig',
    'sales.apps.SalesConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
]

USE_DJANGO_JQUERY = True

我输入了亚洲和欧洲大陆,并将波兰添加到了欧洲,将中国添加到了亚洲。但是,当我尝试添加位置时,第二个下拉列表将不显示该位置。我在做什么错了?

0 个答案:

没有答案