Skip to content

Commit

Permalink
Set WIDGET_MAP for model resources to handle JSON fields
Browse files Browse the repository at this point in the history
backports #9307

fixes #9324

(cherry picked from commit 225360c)
  • Loading branch information
David Davis authored and daviddavis committed Aug 31, 2021
1 parent 03a4e26 commit ad3a286
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES/plugin_api/9324.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Set the default widget type to ``JSONWidget`` for ``JSONFields`` for Model Resources to fix
django-import-export bug where ``django.db.models.JSONFields`` weren't properly handled.
(backported from #9307)
6 changes: 6 additions & 0 deletions pulpcore/plugin/importexport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from import_export import resources
from import_export.resources import widgets


class QueryModelResource(resources.ModelResource):
Expand All @@ -19,6 +20,11 @@ class QueryModelResource(resources.ModelResource):
(driven by repo_version)
"""

# TODO: remove this when https://git.io/JEgMp is released
# This forces JSONField to map to JSONWidget as django-import-export does not properly handle
# JSONField from django.db.models in django-import-export 2.5.0
WIDGETS_MAP = {**resources.ModelResource.WIDGETS_MAP, **{"JSONField": widgets.JSONWidget}}

def set_up_queryset(self):
return None

Expand Down

0 comments on commit ad3a286

Please sign in to comment.