Skip to content

Commit

Permalink
[Dépôt de besoin] Admin : réparer les stats des structures (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn authored Nov 8, 2023
1 parent 2f4bee5 commit 26cf773
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"survey_transactioned_feedback",
"survey_transactioned_answer_date",
"validated_at",
"question_count_annotated_with_link",
"question_count_with_link",
"siae_count_annotated_with_link",
"siae_email_send_count_annotated_with_link",
"siae_email_link_click_count_annotated_with_link",
Expand Down Expand Up @@ -210,7 +210,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"constraints",
"external_link",
"accept_cocontracting",
"question_count_annotated_with_link",
"question_count_with_link",
),
},
),
Expand Down Expand Up @@ -341,7 +341,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
def get_queryset(self, request):
qs = super().get_queryset(request)
qs = qs.with_siae_stats()
qs = qs.with_question_stats()
# qs = qs.with_question_stats() # doesn't work when chaining these 2 querysets: adds duplicates...
return qs

def get_changeform_initial_data(self, request):
Expand Down Expand Up @@ -409,12 +409,11 @@ def user_with_link(self, tender):
user_with_link.short_description = "Auteur"
user_with_link.admin_order_field = "author"

def question_count_annotated_with_link(self, tender):
def question_count_with_link(self, tender):
url = reverse("admin:tenders_tenderquestion_changelist") + f"?tender__in={tender.id}"
return format_html(f'<a href="{url}">{getattr(tender, "question_count_annotated", 0)}</a>')
return format_html(f'<a href="{url}">{tender.questions.count()}</a>')

question_count_annotated_with_link.short_description = TenderQuestion._meta.verbose_name_plural
question_count_annotated_with_link.admin_order_field = "question_count_annotated"
question_count_with_link.short_description = TenderQuestion._meta.verbose_name_plural

def siae_count_annotated_with_link(self, tender):
url = reverse("admin:siaes_siae_changelist") + f"?tenders__in={tender.id}"
Expand Down

0 comments on commit 26cf773

Please sign in to comment.