From e65f30d216fe0106f490f159e8fae82e793cdc79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Reuiller?= Date: Mon, 9 Oct 2023 14:39:30 +0200 Subject: [PATCH] add admin for tender steps data --- lemarche/tenders/admin.py | 22 ++++++++++++++++++- .../migrations/0058_tenderstepsdata.py | 6 ++++- lemarche/tenders/models.py | 7 ++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lemarche/tenders/admin.py b/lemarche/tenders/admin.py index e2cc5286b..88372d08f 100644 --- a/lemarche/tenders/admin.py +++ b/lemarche/tenders/admin.py @@ -16,7 +16,7 @@ from lemarche.perimeters.admin import PerimeterRegionFilter from lemarche.tenders import constants from lemarche.tenders.forms import TenderAdminForm -from lemarche.tenders.models import PartnerShareTender, Tender, TenderQuestion +from lemarche.tenders.models import PartnerShareTender, Tender, TenderQuestion, TenderStepsData from lemarche.utils.admin.admin_site import admin_site from lemarche.utils.apis import api_hubspot from lemarche.utils.fields import ChoiceArrayField, pretty_print_readonly_jsonfield @@ -591,3 +591,23 @@ def logs_display(self, partnersharetender=None): return "-" logs_display.short_description = PartnerShareTender._meta.get_field("logs").verbose_name + + +@admin.register(TenderStepsData, site=admin_site) +class TenderStepsDataAdmin(admin.ModelAdmin): + list_display = ["created_at", "updated_at", "uuid"] + + readonly_fields = [ + "id", + "created_at", + "updated_at", + "uuid", + "steps_data_display", + ] + + def steps_data_display(self, tender_steps_data: TenderStepsData = None): + if tender_steps_data: + return pretty_print_readonly_jsonfield(tender_steps_data.steps_data) + return "-" + + steps_data_display.short_description = "Données saisies dans les étapes" diff --git a/lemarche/tenders/migrations/0058_tenderstepsdata.py b/lemarche/tenders/migrations/0058_tenderstepsdata.py index 3cce3a1fd..d95fd605d 100644 --- a/lemarche/tenders/migrations/0058_tenderstepsdata.py +++ b/lemarche/tenders/migrations/0058_tenderstepsdata.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.2 on 2023-10-05 14:15 +# Generated by Django 4.2.2 on 2023-10-09 12:32 from django.db import migrations, models import django.utils.timezone @@ -36,5 +36,9 @@ class Migration(migrations.Migration): ("updated_at", models.DateTimeField(auto_now=True, verbose_name="Date de modification")), ("steps_data", models.JSONField(default=list, editable=False, verbose_name="Données des étapes")), ], + options={ + "verbose_name": "Besoin d'achat - Données des étapes", + "verbose_name_plural": "Besoins d'achat - Données des étapes", + }, ), ] diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index 68ae4f8ad..9644a6b1a 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -777,3 +777,10 @@ class TenderStepsData(models.Model): auto_created=True, ) steps_data = models.JSONField(verbose_name="Données des étapes", editable=False, default=list) + + class Meta: + verbose_name = "Besoin d'achat - Données des étapes" + verbose_name_plural = "Besoins d'achat - Données des étapes" + + def __str__(self): + return f"{self.uuid} - {self.created_at}"