From bc75f4dd7c6a41c27574249477ef1550f796bb9e Mon Sep 17 00:00:00 2001 From: Ishaan Mittal Date: Tue, 19 Nov 2024 16:28:45 +0530 Subject: [PATCH] add small action for short rebate --- home/admin.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/home/admin.py b/home/admin.py index 695b2bf..df924bd 100644 --- a/home/admin.py +++ b/home/admin.py @@ -540,6 +540,24 @@ def find_overlapping_records(self, request, queryset): return response + def check_negative_days(self, request, queryset): + response = HttpResponse(content_type="text/csv") + response["Content-Disposition"] = 'attachment; filename="Rebate.csv"' + + writer = csv.writer(response) + for obj in queryset: + if (obj.end_date - obj.start_date).days < 0: + writer.writerow( + [ + obj.email, + obj.start_date, + obj.end_date, + getattr(obj.email, "name", None), + ] + ) + + return response + export_as_csv.short_description = "Export Rebate details to CSV"