Skip to content

Commit

Permalink
improve(Achats): Admin: Quelques améliorations dans la vue list (lien…
Browse files Browse the repository at this point in the history
… vers la cantine, colonne Suppr, date de création) (#4791)
  • Loading branch information
raphodn authored Dec 18, 2024
1 parent c02b89a commit b406645
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
5 changes: 1 addition & 4 deletions data/admin/canteen.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CanteenAdmin(SoftDeletionHistoryAdmin):
"source_des_données",
"management_type",
"visible_au_public",
"supprimée",
"deleted",
)
filter_vertical = (
"sectors",
Expand Down Expand Up @@ -152,9 +152,6 @@ def visible_au_public(self, obj):
def source_des_données(self, obj):
return obj.import_source

def supprimée(self, obj):
return "🗑️ Supprimée" if obj.deletion_date else ""


class CanteenInline(admin.TabularInline):
model = Canteen.managers.through
Expand Down
20 changes: 16 additions & 4 deletions data/admin/purchase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html

from data.models import Purchase

Expand All @@ -9,8 +11,8 @@
@admin.register(Purchase)
class PurchaseAdmin(SoftDeletionAdmin):
fields = (
"canteen",
"date",
"canteen",
"description",
"provider",
"family",
Expand All @@ -21,6 +23,7 @@ class PurchaseAdmin(SoftDeletionAdmin):
"local_definition",
"import_source",
"deletion_date",
"creation_date",
)
readonly_fields = (
"canteen",
Expand All @@ -34,14 +37,17 @@ class PurchaseAdmin(SoftDeletionAdmin):
"invoice_file",
"local_definition",
"import_source",
"creation_date",
)
list_display = (
"date",
"canteen_with_link",
"description",
"family",
"characteristics",
"canteen",
"price_ht",
"deleted",
"creation_date",
)
list_filter = (
"family",
Expand All @@ -50,11 +56,17 @@ class PurchaseAdmin(SoftDeletionAdmin):
"deletion_date",
)
search_fields = (
"description",
"canteen__name",
"canteen__siret",
"description",
"import_source",
)
search_help_text = f"Cherche sur les champs : Cantine (SIRET), {Purchase._meta.get_field('description').verbose_name.capitalize()}, {Purchase._meta.get_field('import_source').verbose_name.capitalize()}"

def canteen_name(self, obj):
return obj.canteen.name

def canteen_with_link(self, obj):
url = reverse("admin:data_canteen_change", args=[obj.canteen_id])
return format_html(f'<a href="{url}">{obj.canteen}</a>')

canteen_with_link.short_description = Purchase._meta.get_field("canteen").verbose_name
12 changes: 11 additions & 1 deletion data/admin/softdeletionadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@ def delete_model(self, request, obj):
def delete_queryset(self, request, queryset):
return queryset.hard_delete()

def deleted(self, obj):
return "🗑️ Supprimée" if obj.deletion_date else ""

deleted.short_description = "Supprimée"

def deletion_status(self, obj):
return "🗑️ Supprimée" if obj.deletion_date else "✔️ Active"

deletion_status.short_description = "Statut de suppression"


class SoftDeletionHistoryAdmin(SoftDeletionAdmin, SimpleHistoryAdmin):
pass


class SoftDeletionStatusFilter(admin.SimpleListFilter):
title = "status de suppression par l'utilisateur"
title = "statut de suppression par l'utilisateur"

parameter_name = "deletion_status"

Expand Down

0 comments on commit b406645

Please sign in to comment.