Skip to content

Commit ceb90ee

Browse files
authored
feat: django-import-export 4.0 support (3.x deprecated) (#398)
1 parent 61c60f3 commit ceb90ee

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

src/unfold/contrib/import_export/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def export_action_form_factory(formats):
99
class _ExportActionForm(ActionForm):
10-
file_format = forms.ChoiceField(
10+
format = forms.ChoiceField(
1111
label=" ",
1212
choices=formats,
1313
required=False,
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
from import_export.forms import ExportForm as BaseExportForm
2-
from import_export.forms import ImportForm as BaseImportForm
1+
from import_export.forms import ImportExportFormBase as BaseImportExportFormBase
32
from unfold.widgets import SELECT_CLASSES, UnfoldAdminFileFieldWidget
43

54

6-
class ImportForm(BaseImportForm):
5+
class ImportForm(BaseImportExportFormBase):
76
def __init__(self, *args, **kwargs):
87
super().__init__(*args, **kwargs)
9-
self.fields["import_file"].widget = UnfoldAdminFileFieldWidget()
10-
self.fields["input_format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)
8+
self.fields["resource"].widget = UnfoldAdminFileFieldWidget()
9+
self.fields["format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)
1110

1211

13-
class ExportForm(BaseExportForm):
12+
class ExportForm(BaseImportExportFormBase):
1413
def __init__(self, *args, **kwargs):
1514
super().__init__(*args, **kwargs)
16-
self.fields["file_format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)
15+
self.fields["format"].widget.attrs["class"] = " ".join(SELECT_CLASSES)

src/unfold/contrib/import_export/templates/admin/import_export/export.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{% csrf_token %}
3838

3939
<fieldset class="border border-gray-200 mb-8 rounded-md pt-3 px-3 shadow-sm dark:border-gray-800">
40-
{% include "unfold/helpers/field.html" with field=form.file_format %}
40+
{% include "unfold/helpers/field.html" with field=form.format %}
4141
</fieldset>
4242

4343
<button type="submit" class="bg-primary-600 border border-transparent font-medium px-3 py-2 rounded-md text-sm text-white">

src/unfold/contrib/import_export/templates/admin/import_export/import_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
</p>
2323

2424
<fieldset class="border border-gray-200 mb-8 rounded-md pt-3 px-3 shadow-sm dark:border-gray-800">
25-
{% include "unfold/helpers/field.html" with field=form.import_file %}
25+
{% include "unfold/helpers/field.html" with field=form.resource %}
2626

27-
{% include "unfold/helpers/field.html" with field=form.input_format %}
27+
{% include "unfold/helpers/field.html" with field=form.format %}
2828
</fieldset>
2929

3030

0 commit comments

Comments
 (0)