From 71b58fc5a7cfdf2bbfb2d42e8386200bf9f3f7ad Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 7 Mar 2024 11:05:20 +0100 Subject: [PATCH] Add to admin --- lemarche/companies/admin.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lemarche/companies/admin.py b/lemarche/companies/admin.py index c6d46ba8c..05372f155 100644 --- a/lemarche/companies/admin.py +++ b/lemarche/companies/admin.py @@ -41,12 +41,22 @@ def queryset(self, request, queryset): @admin.register(Company, site=admin_site) class CompanyAdmin(admin.ModelAdmin, DynamicArrayMixin): - list_display = ["id", "name", "user_count_annotated_with_link", "created_at"] + list_display = [ + "id", + "name", + "user_count_annotated_with_link", + "user_tender_count_annotated_with_link", + "created_at", + ] list_filter = [HasUserFilter, HasEmailDomainFilter] search_fields = ["id", "name"] search_help_text = "Cherche sur les champs : ID, Nom" - readonly_fields = ["logo_url_display", "user_count_annotated_with_link", "created_at", "updated_at"] + readonly_fields = [ + "logo_url_display", + "user_count_annotated_with_link", + "user_tender_count_annotated_with_link", + ] + Company.READONLY_FIELDS fieldsets = ( ( @@ -57,6 +67,7 @@ class CompanyAdmin(admin.ModelAdmin, DynamicArrayMixin): ), ("Logo", {"fields": ("logo_url", "logo_url_display")}), ("Utilisateurs", {"fields": ("user_count_annotated_with_link",)}), + ("Besoins", {"fields": ("user_tender_count_annotated_with_link",)}), ("Dates", {"fields": ("created_at", "updated_at")}), ) @@ -93,5 +104,12 @@ def user_count_annotated_with_link(self, company): url = reverse("admin:users_user_changelist") + f"?company__id__exact={company.id}" return format_html(f'{company.user_count_annotated}') - user_count_annotated_with_link.short_description = "Nombre d'utilisateurs rattachés" + user_count_annotated_with_link.short_description = "Utilisateurs rattachés" user_count_annotated_with_link.admin_order_field = "user_count_annotated" + + def user_tender_count_annotated_with_link(self, company): + url = reverse("admin:tenders_tender_changelist") + f"?author__company_id__exact={company.id}" + return format_html(f'{company.user_tender_count_annotated}') + + user_tender_count_annotated_with_link.short_description = "Besoins déposés par les utilisateurs" + user_tender_count_annotated_with_link.admin_order_field = "user_tender_count_annotated"