feat(apps): Add django-import-export

This commit is contained in:
Tom Hubrecht 2024-09-27 10:55:05 +02:00
parent 224f9df858
commit 97dc77fd5d
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
3 changed files with 20 additions and 3 deletions

View file

@ -61,6 +61,7 @@ in
ps.django-bulma-forms
ps.django-compressor
ps.django-debug-toolbar
ps.django-import-export
ps.django-sass-processor
ps.django-sass-processor-dart-sass
ps.django-stubs

View file

@ -28,16 +28,21 @@ ADMINS = credentials.get_json("ADMINS", [])
# List the installed applications
INSTALLED_APPS = [
# Unfold apps
"unfold",
"unfold.contrib.import_export",
# Django standard apps
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
# Custom apps
"shared.staticfiles.StaticFilesApp", # Overrides the default staticfiles app to filter out the sccs sources
"django_browser_reload",
"sass_processor",
"bulma",
"import_export",
# Authentication
"allauth",
"allauth.account",

View file

@ -1,15 +1,26 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from import_export.admin import ImportExportMixin
from unfold.admin import ModelAdmin
from unfold.contrib.import_export.forms import (
ExportForm,
ImportForm,
SelectableFieldsExportForm,
)
from dgsi.models import Bylaws, Service, Statutes, Translation, User
@admin.register(User)
class UserAdmin(BaseUserAdmin, ModelAdmin):
pass
class UserAdmin(BaseUserAdmin, ImportExportMixin, ModelAdmin):
import_form_class = ImportForm
export_form_class = ExportForm
export_form_class = SelectableFieldsExportForm
@admin.register(Bylaws, Service, Statutes, Translation)
class AdminClass(ModelAdmin):
class AdminClass(ImportExportMixin, ModelAdmin):
compressed_fields = True
import_form_class = ImportForm
export_form_class = ExportForm
export_form_class = SelectableFieldsExportForm