lehins / django-smartfields

Django Model Fields that are smart.
MIT License
98 stars 13 forks source link

Django 4.0+ compatibility #34

Open psyferre opened 2 years ago

psyferre commented 2 years ago

This PR should add compatibility for django 4+, after which force_text() was deprecated in favor of force_str(), and url() was deprecated. The re_path() function is a drop-in replacement for url().

There is not currently any test coverage, so I'd appreciate it if anyone has older versions of django they can test with. I'm currently doing my own testing with a recently updated application.

vanities commented 2 years ago

this would be great to have, as I cannot use the library without seeing this error:

Traceback (most recent call last):
  File "/app/./manage.py", line 28, in <module>
    main()
  File "/app/./manage.py", line 24, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
    django.setup()
  File "/usr/local/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/app/accounts/models.py", line 9, in <module>
    from smartfields import fields
  File "/usr/local/lib/python3.10/site-packages/smartfields/fields/__init__.py", line 12, in <module>
    from smartfields.managers import FieldManager
  File "/usr/local/lib/python3.10/site-packages/smartfields/managers.py", line 5, in <module>
    from smartfields.utils import ProcessingError, VALUE_NOT_SET, get_model_name
  File "/usr/local/lib/python3.10/site-packages/smartfields/utils.py", line 6, in <module>
    from django.utils.encoding import force_text
ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/usr/local/lib/python3.10/site-packages/django/utils/encoding.py)
make: *** [migrate] Error 1