Show More
@@ -1,64 +1,74 b'' | |||||
1 | from django.contrib import admin |
|
1 | from django.contrib import admin | |
2 | from boards.models import Post, Tag, Ban, Thread, Banner |
|
2 | from boards.models import Post, Tag, Ban, Thread, Banner | |
3 | from django.utils.translation import ugettext_lazy as _ |
|
3 | from django.utils.translation import ugettext_lazy as _ | |
4 |
|
4 | |||
5 |
|
5 | |||
6 | @admin.register(Post) |
|
6 | @admin.register(Post) | |
7 | class PostAdmin(admin.ModelAdmin): |
|
7 | class PostAdmin(admin.ModelAdmin): | |
8 |
|
8 | |||
9 | list_display = ('id', 'title', 'text', 'poster_ip') |
|
9 | list_display = ('id', 'title', 'text', 'poster_ip') | |
10 | list_filter = ('pub_time',) |
|
10 | list_filter = ('pub_time',) | |
11 | search_fields = ('id', 'title', 'text', 'poster_ip') |
|
11 | search_fields = ('id', 'title', 'text', 'poster_ip') | |
12 | exclude = ('referenced_posts', 'refmap') |
|
12 | exclude = ('referenced_posts', 'refmap') | |
13 | readonly_fields = ('poster_ip', 'threads', 'thread', 'images', 'uid') |
|
13 | readonly_fields = ('poster_ip', 'threads', 'thread', 'images', 'uid') | |
14 |
|
14 | |||
15 | def ban_poster(self, request, queryset): |
|
15 | def ban_poster(self, request, queryset): | |
16 | bans = 0 |
|
16 | bans = 0 | |
17 | for post in queryset: |
|
17 | for post in queryset: | |
18 | poster_ip = post.poster_ip |
|
18 | poster_ip = post.poster_ip | |
19 | ban, created = Ban.objects.get_or_create(ip=poster_ip) |
|
19 | ban, created = Ban.objects.get_or_create(ip=poster_ip) | |
20 | if created: |
|
20 | if created: | |
21 | bans += 1 |
|
21 | bans += 1 | |
22 | self.message_user(request, _('{} posters were banned').format(bans)) |
|
22 | self.message_user(request, _('{} posters were banned').format(bans)) | |
23 |
|
23 | |||
24 | actions = ['ban_poster'] |
|
24 | actions = ['ban_poster'] | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | @admin.register(Tag) |
|
27 | @admin.register(Tag) | |
28 | class TagAdmin(admin.ModelAdmin): |
|
28 | class TagAdmin(admin.ModelAdmin): | |
29 |
|
29 | |||
30 | def thread_count(self, obj: Tag) -> int: |
|
30 | def thread_count(self, obj: Tag) -> int: | |
31 | return obj.get_thread_count() |
|
31 | return obj.get_thread_count() | |
32 |
|
32 | |||
33 | list_display = ('name', 'thread_count') |
|
33 | def display_children(self, obj: Tag): | |
|
34 | return ', '.join([str(child) for child in obj.get_children().all()]) | |||
|
35 | ||||
|
36 | list_display = ('name', 'thread_count', 'display_children') | |||
34 | search_fields = ('name',) |
|
37 | search_fields = ('name',) | |
35 |
|
38 | |||
36 |
|
39 | |||
37 | @admin.register(Thread) |
|
40 | @admin.register(Thread) | |
38 | class ThreadAdmin(admin.ModelAdmin): |
|
41 | class ThreadAdmin(admin.ModelAdmin): | |
39 |
|
42 | |||
40 | def title(self, obj: Thread) -> str: |
|
43 | def title(self, obj: Thread) -> str: | |
41 | return obj.get_opening_post().get_title() |
|
44 | return obj.get_opening_post().get_title() | |
42 |
|
45 | |||
43 | def reply_count(self, obj: Thread) -> int: |
|
46 | def reply_count(self, obj: Thread) -> int: | |
44 | return obj.get_reply_count() |
|
47 | return obj.get_reply_count() | |
45 |
|
48 | |||
46 | def ip(self, obj: Thread): |
|
49 | def ip(self, obj: Thread): | |
47 | return obj.get_opening_post().poster_ip |
|
50 | return obj.get_opening_post().poster_ip | |
48 |
|
51 | |||
49 | list_display = ('id', 'title', 'reply_count', 'archived', 'ip') |
|
52 | def display_tags(self, obj: Thread): | |
|
53 | return ', '.join([str(tag) for tag in obj.get_tags().all()]) | |||
|
54 | ||||
|
55 | def op(self, obj: Thread): | |||
|
56 | return obj.get_opening_post_id() | |||
|
57 | ||||
|
58 | list_display = ('id', 'op', 'title', 'reply_count', 'archived', 'ip', | |||
|
59 | 'display_tags') | |||
50 | list_filter = ('bump_time', 'archived', 'bumpable') |
|
60 | list_filter = ('bump_time', 'archived', 'bumpable') | |
51 | search_fields = ('id', 'title') |
|
61 | search_fields = ('id', 'title') | |
52 | filter_horizontal = ('tags',) |
|
62 | filter_horizontal = ('tags',) | |
53 |
|
63 | |||
54 |
|
64 | |||
55 | @admin.register(Ban) |
|
65 | @admin.register(Ban) | |
56 | class BanAdmin(admin.ModelAdmin): |
|
66 | class BanAdmin(admin.ModelAdmin): | |
57 | list_display = ('ip', 'can_read') |
|
67 | list_display = ('ip', 'can_read') | |
58 | list_filter = ('can_read',) |
|
68 | list_filter = ('can_read',) | |
59 | search_fields = ('ip',) |
|
69 | search_fields = ('ip',) | |
60 |
|
70 | |||
61 |
|
71 | |||
62 | @admin.register(Banner) |
|
72 | @admin.register(Banner) | |
63 | class BannerAdmin(admin.ModelAdmin): |
|
73 | class BannerAdmin(admin.ModelAdmin): | |
64 | list_display = ('title', 'text') |
|
74 | list_display = ('title', 'text') |
General Comments 0
You need to be logged in to leave comments.
Login now