From 3d2bceb65d7b0df0b1076afc9f48a4c60a7b83a7 Mon Sep 17 00:00:00 2001 From: monodo Date: Wed, 29 May 2024 13:09:38 +0200 Subject: [PATCH] Feature/fix admin field order (#1011) * upgrade to jazzmin 3 * wip: fix drag & drop * teak css for jazzmin + admin-sortable2 * fix css to not impact other pages, and make interface easier to use --------- Co-authored-by: AlexandreJunod --- geocity/apps/core/static/css/admin/admin.css | 36 ++++++++++++++++++-- geocity/apps/forms/admin.py | 7 ++-- geocity/apps/forms/models.py | 3 ++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/geocity/apps/core/static/css/admin/admin.css b/geocity/apps/core/static/css/admin/admin.css index 165f5984b..1565d3ed8 100644 --- a/geocity/apps/core/static/css/admin/admin.css +++ b/geocity/apps/core/static/css/admin/admin.css @@ -11,7 +11,37 @@ overflow-x: auto; } -/*Reduce select2 field width so that CRUD button remain visible*/ -tr .select2 { - width: 70% !important; +/* tweak admin-sortable2 for jazzmin compatibility with tabular inlines */ +/* Used in "1.4 Formulaires", tab "Champs" */ + +fieldset.module.sortable tbody tr.form-row { + padding: 20px 0px 10px 0px; /* top right bottom left*/ + border-bottom: 1px dashed #c7c7c7; +} + +fieldset.module.sortable tbody .original { + width: 50px; + text-align: center; +} + +fieldset.module.sortable td.original p { + width: 45px !important; +} + +fieldset.module.sortable tbody .field-field { + width: 650px; +} + +fieldset.module.sortable tbody .delete { + width: 50px; /* width of div. (thead .original - tbody.original - tbody .field-field)*/ + position: relative; /* used to move 50 px left */ + left: 75px; +} + +fieldset.module.sortable thead .original { + width: 750px; +} + +fieldset.module.sortable thead .column-field { + display: none; } diff --git a/geocity/apps/forms/admin.py b/geocity/apps/forms/admin.py index d7396111b..00becb393 100644 --- a/geocity/apps/forms/admin.py +++ b/geocity/apps/forms/admin.py @@ -1,7 +1,7 @@ import string import django.db.models -from adminsortable2.admin import SortableAdminMixin, SortableInlineAdminMixin +from adminsortable2.admin import SortableAdminMixin, SortableTabularInline from constance import config from django import forms from django.contrib import admin @@ -178,8 +178,7 @@ def save(self, *args, **kwargs): return super().save(*args, **kwargs) -# TODO: enable drag and drop for inline reorder -class FormFieldInline(admin.TabularInline, SortableInlineAdminMixin): +class FormFieldInline(SortableTabularInline): model = models.FormField extra = 2 verbose_name = _("Champ") @@ -198,7 +197,7 @@ class Media: css = {"all": ("css/admin/admin.css",)} -class FormPricesInline(admin.TabularInline, SortableInlineAdminMixin): +class FormPricesInline(admin.TabularInline): model = models.Form.prices.through extra = 1 verbose_name = _("Tarif") diff --git a/geocity/apps/forms/models.py b/geocity/apps/forms/models.py index c2603f591..3d58c8a44 100644 --- a/geocity/apps/forms/models.py +++ b/geocity/apps/forms/models.py @@ -820,6 +820,9 @@ class Meta: verbose_name_plural = _("Champs du formulaire") ordering = ("order",) + def __str__(self): + return str(self.order) + # Input types INPUT_TYPE_ADDRESS = "address"