Skip to content

Commit 98ee0ce

Browse files
committed
add search_field to paymentRequest
1 parent 7bf2bb4 commit 98ee0ce

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Diff for: backend/payment/admin.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
from payment.models import PaymentDiscount, PaymentRequest
1111
from core.models import Event
1212

13+
1314
# Register your models here.
1415

1516
class CsvImportForm(forms.Form):
1617
csv_file = forms.FileField()
1718

19+
1820
class PaymentDiscountAdmin(admin.ModelAdmin, ExportCSVMixin):
1921
search_fields = ('code',)
2022
list_display = ('code', 'percentage', 'amount', 'count')
@@ -49,23 +51,33 @@ def get_urls(self):
4951
]
5052
return my_urls + urls
5153

54+
5255
admin.site.register(PaymentDiscount, PaymentDiscountAdmin)
5356

57+
5458
class DiscountCodesImportForm(forms.Form):
5559
file = forms.FileField()
5660

61+
5762
class PaymentRequestAdmin(admin.ModelAdmin, ExportCSVMixin):
58-
list_display = ('participant', 'timestamp', 'paid', 'discount_code', 'order_id', 'base_price', 'paid_price')
63+
list_display = ('participant', 'timestamp', 'paid', 'discount__code', 'order_id', 'base_price', 'paid_price')
5964
list_filter = ('paid', 'discount__code')
6065
actions = ["export_as_csv", "calculate_discount_usage"]
6166
change_list_template = "payment_request_changelist.html"
67+
search_fields = (
68+
'participant__user__email',
69+
'participant__info__first_name',
70+
'participant__info__last_name',
71+
'order_id',
72+
'discount__code',
73+
)
6274

6375
def base_price(self, obj):
6476
return obj.get_price()[0]
65-
77+
6678
def paid_price(self, obj):
6779
return obj.get_price()[1]
68-
80+
6981
def discount_code(self, obj):
7082
return obj.discount.code if obj.discount is not None else None
7183

@@ -88,7 +100,7 @@ def calculate_discount_usage(self, request, queryset):
88100

89101
for discount in discount_codes:
90102
total_usage = queryset.filter(discount=discount).count()
91-
103+
92104
successful_payments = queryset.filter(
93105
discount=discount,
94106
paid=True
@@ -111,7 +123,7 @@ def import_discount_codes(self, request):
111123
file = request.FILES["file"]
112124
content = file.read().decode('utf-8')
113125
discount_codes = [code.strip() for code in content.split('\n') if code.strip()]
114-
126+
115127
response = HttpResponse(content_type='text/csv')
116128
response['Content-Disposition'] = 'attachment; filename=discount_usage_report.csv'
117129
writer = csv.writer(response)
@@ -159,4 +171,5 @@ def get_urls(self):
159171
]
160172
return my_urls + urls
161173

162-
admin.site.register(PaymentRequest, PaymentRequestAdmin)
174+
175+
admin.site.register(PaymentRequest, PaymentRequestAdmin)

0 commit comments

Comments
 (0)