-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadmin.py
68 lines (61 loc) · 1.66 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from payments import PaymentStatus
from plans.models import Order
from related_admin import RelatedFieldAdmin
from . import models
class FaultyPaymentsFilter(SimpleListFilter):
title = "faulty_payments"
parameter_name = "faulty_payments"
def lookups(self, request, model_admin):
return [
("unconfirmed_order", "Confirmed payment unconfirmed order"),
]
def queryset(self, request, queryset):
if self.value() == "unconfirmed_order":
return queryset.filter(status=PaymentStatus.CONFIRMED).exclude(
order__status=Order.STATUS.COMPLETED
)
return queryset
@admin.register(models.Payment)
class PaymentAdmin(RelatedFieldAdmin):
list_display = (
"id",
"transaction_id",
"token",
"order__user",
"variant",
"status",
"fraud_status",
"currency",
"total",
"customer_ip_address",
"tax",
"transaction_fee",
"captured_amount",
"created",
"modified",
"autorenewed_payment",
)
list_filter = (
"status",
"variant",
"fraud_status",
"currency",
"autorenewed_payment",
FaultyPaymentsFilter,
)
search_fields = (
"order__user__first_name",
"order__user__last_name",
"order__user__email",
"transaction_id",
"extra_data",
"token",
)
list_select_related = ("order__user",)
autocomplete_fields = ("order",)
readonly_fields = (
"created",
"modified",
)