Answer the question
In order to leave comments, you need to log in
Why doesn't Django accept ChainedForeignKey?
Good afternoon everyone. Decided to create dependent dropdown lists using Chained Selects.
I read all the documentation, followed all the points, namely:
1. Installed pip install django-smart-selects
2. Added smart_selects to INSTALLED_APPS
3. Added path('chaining/', include('smart_selects.urls')) to urls.py ,
4. Added to settings.py JQUERY_URL = True
I change my model:
from django.contrib.auth.models import User
from django.db import models
from smart_selects.db_fields import ChainedForeignKey
class Brand(models.Model):
brand_name = models.CharField(max_length=30, unique=True)
brand_country = models.CharField(max_length=30)
brand_history = models.TextField()
brand_logo = models.ImageField(verbose_name='Логотип', upload_to='logo/', null=True)
class Model(models.Model):
model_brand = models.ForeignKey(Brand, on_delete=models.CASCADE, null=True)
model_name = models.CharField(max_length=30, unique=True)
class Car(models.Model):
car_brand = models.ForeignKey(Brand, on_delete=models.CASCADE, verbose_name='Марка')
car_model = models.ChainedForeignKey(Model,
chained_field="car_brand",
chained_model_field="Brand",
on_delete=models.CASCADE,
verbose_name='Модель')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question