openwisp-controller
openwisp-controller copied to clipboard
[models] Replace thirdparty JSONField with Django built-in JSONField
Checklist
- [x] I have read the OpenWISP Contributing Guidelines.
- [x] I have manually tested the changes proposed in this pull request.
- [ ] I have written new test cases for new code and/or updated existing tests for changes to existing code.
- [ ] I have updated the documentation.
Reference to Existing Issue
Closes #1061.
Description of Changes
This PR replaces the third-party jsonfield package with Django's built-in JSONField across all OpenWISP controller models to modernize the codebase and remove dependency on an unmaintained package.
Changes Made:
-
Updated 6 model files to use
django.db.models.JSONFieldinstead of third-partyjsonfield.JSONField:openwisp_controller/config/base/base.pyopenwisp_controller/config/base/config.pyopenwisp_controller/config/base/device_group.pyopenwisp_controller/config/base/multitenancy.pyopenwisp_controller/config/base/template.pyopenwisp_controller/connection/base/models.py
-
Created 2 migration files to safely alter field types:
openwisp_controller/config/migrations/0061_replace_jsonfield_with_django_builtin.pyopenwisp_controller/connection/migrations/0010_replace_jsonfield_with_django_builtin.py
-
Removed jsonfield-specific parameters (
load_kwargs,dump_kwargs) that are not supported by Django's JSONField -
Fixed code quality issues by removing unused imports and duplicate imports
Technical Details:
- Django's
JSONFieldhandles JSON serialization internally without needing external parameters - The
load_kwargs={"object_pairs_hook": collections.OrderedDict}is no longer needed as Python 3.7+ dicts maintain insertion order - The
dump_kwargs={"indent": 4}formatting should be handled at the serialization/display layer, not the model level - All existing JSON data remains compatible and accessible