##// END OF EJS Templates
Don't list all threads to filter posts by
neko259 -
r969:783c920b default
parent child Browse files
Show More
@@ -1,59 +1,59 b''
1 from django.contrib import admin
1 from django.contrib import admin
2 from boards.models import Post, Tag, Ban, Thread
2 from boards.models import Post, Tag, Ban, Thread
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')
9 list_display = ('id', 'title', 'text')
10 list_filter = ('pub_time', 'thread_new')
10 list_filter = ('pub_time',)
11 search_fields = ('id', 'title', 'text')
11 search_fields = ('id', 'title', 'text')
12 exclude = ('referenced_posts', 'refmap')
12 exclude = ('referenced_posts', 'refmap')
13 readonly_fields = ('poster_ip', 'thread_new')
13 readonly_fields = ('poster_ip', 'thread_new')
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 list_display = ('name', 'thread_count')
34 search_fields = ('name',)
34 search_fields = ('name',)
35
35
36
36
37 @admin.register(Thread)
37 @admin.register(Thread)
38 class ThreadAdmin(admin.ModelAdmin):
38 class ThreadAdmin(admin.ModelAdmin):
39
39
40 def title(self, obj: Thread) -> str:
40 def title(self, obj: Thread) -> str:
41 return obj.get_opening_post().get_title()
41 return obj.get_opening_post().get_title()
42
42
43 def reply_count(self, obj: Thread) -> int:
43 def reply_count(self, obj: Thread) -> int:
44 return obj.get_reply_count()
44 return obj.get_reply_count()
45
45
46 def ip(self, obj: Thread):
46 def ip(self, obj: Thread):
47 return obj.get_opening_post().poster_ip
47 return obj.get_opening_post().poster_ip
48
48
49 list_display = ('id', 'title', 'reply_count', 'archived', 'ip')
49 list_display = ('id', 'title', 'reply_count', 'archived', 'ip')
50 list_filter = ('bump_time', 'archived', 'bumpable')
50 list_filter = ('bump_time', 'archived', 'bumpable')
51 search_fields = ('id', 'title')
51 search_fields = ('id', 'title')
52 filter_horizontal = ('tags',)
52 filter_horizontal = ('tags',)
53
53
54
54
55 @admin.register(Ban)
55 @admin.register(Ban)
56 class BanAdmin(admin.ModelAdmin):
56 class BanAdmin(admin.ModelAdmin):
57 list_display = ('ip', 'can_read')
57 list_display = ('ip', 'can_read')
58 list_filter = ('can_read',)
58 list_filter = ('can_read',)
59 search_fields = ('ip',)
59 search_fields = ('ip',)
General Comments 0
You need to be logged in to leave comments. Login now