-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
120 lines (104 loc) · 2.21 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from django.contrib import admin
from .models import Contact, Message, BulkMail
@admin.register(Contact)
class ContactAdmin(admin.ModelAdmin):
fields = (
"id",
"slug",
"user",
"email",
"firstname",
"lastname",
"username",
"domain",
)
readonly_fields = (
"id",
"user",
"slug",
"username",
"domain",
)
list_display = fields
@admin.register(Message)
class MessageAdmin(admin.ModelAdmin):
list_display = (
"id",
"slug",
"user",
"sender",
"_to",
"_cc",
"_bcc",
"subject",
"sent",
)
list_editable = ()
ordering = ("id",)
def get_fields(self, request, obj=None):
if obj:
return [
"id",
"slug",
"user",
"sender",
"_to",
"_cc",
"_bcc",
"subject",
"message",
"sent",
]
return [
"id",
"slug",
"user",
"sender",
"to",
"cc",
"bcc",
"subject",
"message",
"sent",
]
def get_readonly_fields(self, request, obj=None):
if obj:
return self.get_fields(request, obj)
return ["id", "slug", "user", "sent"]
@staticmethod
def _to(obj):
return obj.emailstr("to")
@staticmethod
def _cc(obj):
return obj.emailstr("cc")
@staticmethod
def _bcc(obj):
return obj.emailstr("bcc")
@admin.register(BulkMail)
class BulkMailAdmin(admin.ModelAdmin):
fields = (
"id",
"slug",
"user",
"sender",
"target",
"cc",
"bcc",
"subject",
"sent",
)
list_display = (
"id",
"slug",
"user",
"sender",
"target_count",
"subject",
"sent",
)
list_editable = ()
ordering = ("-id",)
def get_readonly_fields(self, request, obj=None):
if obj:
return self.fields
return ["id", "slug", "user", "sent"]