From ef6bc4efee853f5e3412702aa0a92c6ac15d1452 Mon Sep 17 00:00:00 2001 From: Kseninia Mikhaylova Date: Wed, 4 Sep 2024 08:56:57 +0300 Subject: [PATCH] import export --- back/back/settings.py | 3 +++ back/object/admin.py | 11 +++++--- poetry.lock | 62 ++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/back/back/settings.py b/back/back/settings.py index 99a1237..aba98b0 100644 --- a/back/back/settings.py +++ b/back/back/settings.py @@ -84,6 +84,7 @@ INSTALLED_APPS = [ "crispy_forms", "crispy_bootstrap4", "colorfield", + 'import_export', "frontImages", "object", ] @@ -184,6 +185,8 @@ REST_FRAMEWORK = { CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4" CRISPY_TEMPLATE_PACK = "bootstrap4" +IMPORT_EXPORT_USE_TRANSACTIONS = True + DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" LOGGING = { "version": 1, diff --git a/back/object/admin.py b/back/object/admin.py index 1bad528..c39d1a8 100644 --- a/back/object/admin.py +++ b/back/object/admin.py @@ -1,12 +1,15 @@ from django.contrib import admin +from import_export.admin import ImportExportModelAdmin from .models import ClickableArea, Element3D, Environment, Scene3D -class Scene3DAdmin(admin.ModelAdmin): +class Scene3DAdmin(ImportExportModelAdmin, admin.ModelAdmin): filter_horizontal = ("elements",) +class ImportExportBtnAdmin(ImportExportModelAdmin, admin.ModelAdmin): + pass -admin.site.register(Environment) +admin.site.register(Environment, ImportExportBtnAdmin) admin.site.register(Scene3D, Scene3DAdmin) -admin.site.register(Element3D) -admin.site.register(ClickableArea) +admin.site.register(Element3D, ImportExportBtnAdmin) +admin.site.register(ClickableArea, ImportExportBtnAdmin) diff --git a/poetry.lock b/poetry.lock index ccf3497..d9150c7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -43,6 +43,20 @@ files = [ django = ">=4.2" django-crispy-forms = ">=2.0" +[[package]] +name = "diff-match-patch" +version = "20230430" +description = "Diff Match and Patch" +optional = false +python-versions = ">=3.7" +files = [ + {file = "diff-match-patch-20230430.tar.gz", hash = "sha256:953019cdb9c9d2c9e47b5b12bcff3cf4746fc4598eb406076fa1fc27e6a1f15c"}, + {file = "diff_match_patch-20230430-py3-none-any.whl", hash = "sha256:dce43505fb7b1b317de7195579388df0746d90db07015ed47a85e5e44930ef93"}, +] + +[package.extras] +dev = ["attribution (==1.6.2)", "black (==23.3.0)", "flit (==3.8.0)", "mypy (==1.2.0)", "ufmt (==2.1.0)", "usort (==1.0.6)"] + [[package]] name = "django" version = "5.0.6" @@ -134,6 +148,31 @@ files = [ [package.dependencies] Django = ">=4.2" +[[package]] +name = "django-import-export" +version = "4.1.1" +description = "Django application and library for importing and exporting data with included admin integration." +optional = false +python-versions = ">=3.8" +files = [ + {file = "django_import_export-4.1.1-py3-none-any.whl", hash = "sha256:730ae2443a02b1ba27d8dba078a27ae9123adfcabb78161b4f130843607b3df9"}, + {file = "django_import_export-4.1.1.tar.gz", hash = "sha256:16ecc5a9f0df46bde6eb278a3e65ebda0ee1db55656f36440e9fb83f40ab85a3"}, +] + +[package.dependencies] +diff-match-patch = "*" +Django = ">=3.2" +tablib = "3.5.0" + +[package.extras] +all = ["tablib[all] (==3.5.0)"] +cli = ["tablib[cli]"] +ods = ["tablib[ods]"] +pandas = ["tablib[pandas]"] +xls = ["tablib[xls] (==3.5.0)"] +xlsx = ["tablib[xlsx] (==3.5.0)"] +yaml = ["tablib[yaml] (==3.5.0)"] + [[package]] name = "djangorestframework" version = "3.15.1" @@ -324,6 +363,27 @@ files = [ dev = ["build", "hatch"] doc = ["sphinx"] +[[package]] +name = "tablib" +version = "3.5.0" +description = "Format agnostic tabular data library (XLS, JSON, YAML, CSV, etc.)" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tablib-3.5.0-py3-none-any.whl", hash = "sha256:9821caa9eca6062ff7299fa645e737aecff982e6b2b42046928a6413c8dabfd9"}, + {file = "tablib-3.5.0.tar.gz", hash = "sha256:f6661dfc45e1d4f51fa8a6239f9c8349380859a5bfaa73280645f046d6c96e33"}, +] + +[package.extras] +all = ["markuppy", "odfpy", "openpyxl (>=2.6.0)", "pandas", "pyyaml", "tabulate", "xlrd", "xlwt"] +cli = ["tabulate"] +html = ["markuppy"] +ods = ["odfpy"] +pandas = ["pandas"] +xls = ["xlrd", "xlwt"] +xlsx = ["openpyxl (>=2.6.0)"] +yaml = ["pyyaml"] + [[package]] name = "taskipy" version = "1.12.2" @@ -377,4 +437,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "e2a879fbbc841d8bceb6c622ba4fefd3930ffe8944faa0c9a3c9e976bbd7dd34" +content-hash = "721ce91ef3ad82e5b07e5c1c94740541e5edc6250a4c6c51fcfa5ff2ab2cc290" diff --git a/pyproject.toml b/pyproject.toml index 297774a..a5fa80f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ django-crispy-forms = "^2.2" crispy-bootstrap4 = "^2024.1" django-extensions = "^3.2.3" django-colorfield = "^0.11.0" +django-import-export = "^4.1.1" [build-system]