R
R
Razer15112021-10-10 17:00:16
Django
Razer1511, 2021-10-10 17:00:16

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='Модель')


I get an error:

AttributeError: module 'django.db.models' has no attribute 'ChainedForeignKey'

How to solve, tell me please?

Documentation link: https://github.com/jazzband/django-smart-selects

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-10-10
@Razer1511

models.ChainedForeignKeyjust replace with ChainedForeignKey
You have already imported the field, especially from another library

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question