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

ChainedModelChoiceField.choices initialization incompatibility with Django 5.0 #353

Open Dmitri-Sintsov opened 6 months ago

Dmitri-Sintsov commented 6 months ago

Checklist

Steps to reproduce

The following error is being produced while the initialization of Django 5.0 project:

 File "/home/user/work/ispdevenv/lib/python3.10/site-packages/smart_selects/db_fields.py", line 8, in <module>
    from smart_selects import form_fields
  File "/home/user/work/ispdevenv/lib/python3.10/site-packages/smart_selects/form_fields.py", line 10, in <module>
    class ChainedModelChoiceField(ModelChoiceField):
  File "/home/user/work/ispdevenv/lib/python3.10/site-packages/smart_selects/form_fields.py", line 62, in ChainedModelChoiceField
    choices = property(_get_choices, ChoiceField._set_choices)
AttributeError: type object 'ChoiceField' has no attribute '_set_choices'

Actual behavior

Impossible to initialize ChainedModelChoiceField.choices.

Expected behavior

Used to work fine with Django<5.0

See https://github.com/django/django/commit/500e01073adda32d5149624ee9a5cb7aa3d3583f for the reference.

djruesch commented 5 months ago

Anyone have an ETA when this will be fixed for Django 5.0+

lguariento commented 3 months ago

Hello, same issue here. Is there a temporary workaround at least?

lguariento commented 3 months ago

I have renamed ChoiceField._set_choices into ChoiceField.choices. That did the trick!

rickylenon commented 2 months ago

I have renamed ChoiceField._set_choices into ChoiceField.choices. That did the trick!

This works with me. But i get error: bool' object has no attribute 'startswith'

My workaround is to change something under class JqueryMediaMixin line 50: ... media += Media(js=js) return media

replace with: ..make sure js is string type.. if isinstance(js, str): media += Media(js=js) return media

now it works!

PS: File to edit: ..site-packages/smart_selects/widgets.py

yardensachs commented 2 months ago

its fixed in 1.7.1, but v1.7.1 is not in pypi, you need to install from github

Sinanaltundag commented 1 month ago

its fixed in 1.7.1, but v1.7.1 is not in pypi, you need to install from github

I install 1.7.1 from github but it has a problem on django admin

Django Version: | 5.0.6 NoReverseMatch Reverse for 'chained_filter' not found. 'chained_filter' is not a valid view function or pattern name. C:...\Lib\site-packages\django\urls\resolvers.py, line 851, in _reverse_with_prefix django.contrib.admin.options.change_view C:...\Scripts\python.exe 3.11.3

lguariento commented 1 month ago

Have you had a look at this?

Sinanaltundag commented 1 month ago

Thanks for explanation. @lguariento

Additionally I think documentation must be updated. installation progress is very old. for django 5;

for settings.py

USE_DJANGO_JQUERY = True

for urls.py

urlpatterns = [
    path("admin/", admin.site.urls),
    path('smart_selects/', include('smart_selects.urls')),
]
aijazmahdavi commented 4 weeks ago

I have renamed ChoiceField._set_choices into ChoiceField.choices. That did the trick!

this has an issue, if we are working on local and live then u need to edit files in env which is not recommended

lguariento commented 4 weeks ago

Of course, it's just a temporary workaround. Hopefully it'll officially fixed soon.