Skip to content

Commit

Permalink
Add to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 7, 2024
1 parent 0dbe882 commit 71b58fc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lemarche/companies/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
(
Expand All @@ -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")}),
)

Expand Down Expand Up @@ -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'<a href="{url}">{company.user_count_annotated}</a>')

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'<a href="{url}">{company.user_tender_count_annotated}</a>')

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"

0 comments on commit 71b58fc

Please sign in to comment.