##// END OF EJS Templates
Cleaned up admin site. Update thread's tags list when it is saved
neko259 -
r906:0d5b83db default
parent child Browse files
Show More
@@ -2,18 +2,24 b' from django.contrib import admin'
2 from boards.models import Post, Tag, Ban, Thread
2 from boards.models import Post, Tag, Ban, Thread
3
3
4
4
5 @admin.register(Post)
5 class PostAdmin(admin.ModelAdmin):
6 class PostAdmin(admin.ModelAdmin):
6
7
7 list_display = ('id', 'title', 'text')
8 list_display = ('id', 'title', 'text')
8 list_filter = ('pub_time', 'thread_new')
9 list_filter = ('pub_time', 'thread_new')
9 search_fields = ('id', 'title', 'text')
10 search_fields = ('id', 'title', 'text')
11 exclude = ('referenced_posts', 'refmap')
12 readonly_fields = ('poster_ip', 'thread_new')
10
13
11
14
15 @admin.register(Tag)
12 class TagAdmin(admin.ModelAdmin):
16 class TagAdmin(admin.ModelAdmin):
13
17
14 list_display = ('name',)
18 list_display = ('name',)
19 search_fields = ('name',)
15
20
16
21
22 @admin.register(Thread)
17 class ThreadAdmin(admin.ModelAdmin):
23 class ThreadAdmin(admin.ModelAdmin):
18
24
19 def title(self, obj):
25 def title(self, obj):
@@ -22,17 +28,16 b' class ThreadAdmin(admin.ModelAdmin):'
22 def reply_count(self, obj):
28 def reply_count(self, obj):
23 return obj.get_reply_count()
29 return obj.get_reply_count()
24
30
25 list_display = ('id', 'title', 'reply_count', 'archived')
31 def ip(self, obj):
26 list_filter = ('bump_time', 'archived')
32 return obj.get_opening_post().poster_ip
33
34 list_display = ('id', 'title', 'reply_count', 'archived', 'ip')
35 list_filter = ('bump_time', 'archived', 'bumpable')
27 search_fields = ('id', 'title')
36 search_fields = ('id', 'title')
28
37
29
38
39 @admin.register(Ban)
30 class BanAdmin(admin.ModelAdmin):
40 class BanAdmin(admin.ModelAdmin):
31 list_display = ('ip', 'can_read')
41 list_display = ('ip', 'can_read')
32 list_filter = ('can_read',)
42 list_filter = ('can_read',)
33 search_fields = ('ip',)
43 search_fields = ('ip',) No newline at end of file
34
35 admin.site.register(Post, PostAdmin)
36 admin.site.register(Tag, TagAdmin)
37 admin.site.register(Ban, BanAdmin)
38 admin.site.register(Thread, ThreadAdmin)
@@ -138,10 +138,6 b' class Thread(models.Model):'
138 self.tags.add(tag)
138 self.tags.add(tag)
139 tag.threads.add(self)
139 tag.threads.add(self)
140
140
141 def remove_tag(self, tag):
142 self.tags.remove(tag)
143 tag.threads.remove(self)
144
145 def get_opening_post(self, only_id=False):
141 def get_opening_post(self, only_id=False):
146 """
142 """
147 Gets the first post of the thread
143 Gets the first post of the thread
@@ -185,3 +181,11 b' class Thread(models.Model):'
185
181
186 def __str__(self):
182 def __str__(self):
187 return 'T#{}/{}'.format(self.id, self.get_opening_post_id())
183 return 'T#{}/{}'.format(self.id, self.get_opening_post_id())
184
185 def save(self, force_insert=False, force_update=False, using=None,
186 update_fields=None):
187 super().save(force_insert, force_update, using, update_fields)
188
189 if not update_fields or 'tags' in update_fields:
190 for tag in self.tags.all():
191 tag.threads.add(self) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now