jazzband / django-smart-selects

chained and grouped selects for django forms
https://django-smart-selects.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.1k stars 348 forks source link

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils' #293

Closed albixhafa closed 4 years ago

albixhafa commented 4 years ago

0

Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1

I configured using the official installation guide.

enter code here $ python manage.py runserver
    Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
        self.run()
      File "/usr/lib/python3.7/threading.py", line 865, in run
        self._target(*self._args, **self._kwargs)
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
        fn(*args, **kwargs)
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
        raise _exception[1]
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
        autoreload.check_errors(django.setup)()
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper
        fn(*args, **kwargs)
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
        app_config.import_models()
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
        self.models_module = import_module(models_module_name)
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
      File "<frozen importlib._bootstrap>", line 983, in _find_and_load
      File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 728, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/home/mxcloud3/Desktop/django/polls/models.py", line 2, in <module>
        from smart_selects.db_fields import GroupedForeignKey
      File "/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/smart_selects/db_fields.py", line 6, in <module>
        from django.utils import six
    ImportError: cannot import name 'six' from 'django.utils' (/home/mxcloud3/Desktop/django/venv/lib/python3.7/site-packages/django/utils/__init__.py)

Snippets of code

models.py

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

class Recipe(models.Model):
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    subcategory = GroupedForeignKey(Subcategory, "category", on_delete=models.CASCADE)

settings.py

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'smart_selects',
]

JQUERY_URL = True
manelclos commented 4 years ago

Thanks @xhaxhi, I'd say this is already fixed in this PR: https://github.com/jazzband/django-smart-selects/pull/290

Maybe you want to try it out.

albixhafa commented 4 years ago

This is the wrong place to ask but how come there in not a single piece of documentation on ChainedModelChoiceField ? how are we supposed to use this on templates?

manelclos commented 4 years ago

@xhaxhi well yes, your question is about a different issue. Anyway, ChainedModelChoiceField is a form field, it is used automatically when you define a ChainedForeignKey, documentation for ChainedForeignKey is on the README.md file.

Please open a different issue if you need more help on this. Also, please explain what are trying to do and/or the error problem you are facing.

If the original issue (import error) is fixed for you, please consider closing it.

albixhafa commented 4 years ago

I installed it on Django 2.2.9 with no issues and I am assuming its not compatible with Django 3 yet. Works perfectly on the admin with the documentation provided but I cant get it to work on forms.py since there is no documentation :(

albixhafa commented 4 years ago

I finally figured it and it works for Django 2.2.9!! In order to use it in forms i took the following steps : 1) go to file venv/lib/python3.7/site-packages/django/forms/boundfield.py 2) go to line 93 and comment out

renderer=self.form.renderer,

Btw what is the official Django release supported by the latest version of smart selects 1.5.4?