Skip to content

Commit

Permalink
Add field to queryset & admin
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 15, 2024
1 parent 4cb9190 commit a08520b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lemarche/siaes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def lookup_allowed(self, lookup, *args, **kwargs):
"tendersiae__detail_display_date__isnull",
"tendersiae__detail_contact_click_date__isnull",
"tendersiae__detail_cocontracting_click_date__isnull",
"tendersiae__detail_not_interested_click_date__isnull",
]:
return True
return super().lookup_allowed(lookup, *args, **kwargs)
Expand Down
17 changes: 17 additions & 0 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"siae_email_link_click_or_detail_display_count_annotated_with_link",
"siae_detail_contact_click_count_annotated_with_link",
"siae_detail_cocontracting_click_count_annotated_with_link",
"siae_detail_not_interested_click_count_annotated_with_link",
"logs_display",
"extra_data_display",
"source",
Expand Down Expand Up @@ -302,6 +303,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"siae_email_link_click_or_detail_display_count_annotated_with_link",
"siae_detail_contact_click_count_annotated_with_link",
"siae_detail_cocontracting_click_count_annotated_with_link",
"siae_detail_not_interested_click_count_annotated_with_link",
)
},
),
Expand Down Expand Up @@ -375,6 +377,7 @@ def lookup_allowed(self, lookup, *args, **kwargs):
"tendersiae__detail_display_date__isnull",
"tendersiae__detail_contact_click_date__isnull",
"tendersiae__detail_cocontracting_click_date__isnull",
"tendersiae__detail_not_interested_click_date__isnull",
]:
return True
return super().lookup_allowed(lookup, *args, **kwargs)
Expand Down Expand Up @@ -515,6 +518,20 @@ def siae_detail_cocontracting_click_count_annotated_with_link(self, tender):
"siae_detail_cocontracting_click_count_annotated"
)

def siae_detail_not_interested_click_count_annotated_with_link(self, tender):
url = (
reverse("admin:siaes_siae_changelist")
+ f"?tenders__in={tender.id}&tendersiae__detail_not_interested_click_date__isnull=False"
)
return format_html(
f'<a href="{url}">{getattr(tender, "siae_detail_not_interested_click_count_annotated", 0)}</a>'
)

siae_detail_not_interested_click_count_annotated_with_link.short_description = "S. pas intéressées"
siae_detail_not_interested_click_count_annotated_with_link.admin_order_field = (
"siae_detail_not_interested_click_count_annotated"
)

def logs_display(self, tender=None):
if tender:
return pretty_print_readonly_jsonfield(tender.logs)
Expand Down
7 changes: 7 additions & 0 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ def with_siae_stats(self):
output_field=IntegerField(),
)
),
siae_detail_not_interested_click_count_annotated=Sum(
Case(
When(tendersiae__detail_not_interested_click_date__isnull=False, then=1),
default=0,
output_field=IntegerField(),
)
),
siae_detail_contact_click_since_last_seen_date_count_annotated=Sum(
Case(
When(
Expand Down

0 comments on commit a08520b

Please sign in to comment.