diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -2,18 +2,24 @@ from django.contrib import admin from boards.models import Post, Tag, Ban, Thread +@admin.register(Post) class PostAdmin(admin.ModelAdmin): list_display = ('id', 'title', 'text') list_filter = ('pub_time', 'thread_new') search_fields = ('id', 'title', 'text') + exclude = ('referenced_posts', 'refmap') + readonly_fields = ('poster_ip', 'thread_new') +@admin.register(Tag) class TagAdmin(admin.ModelAdmin): list_display = ('name',) + search_fields = ('name',) +@admin.register(Thread) class ThreadAdmin(admin.ModelAdmin): def title(self, obj): @@ -22,17 +28,16 @@ class ThreadAdmin(admin.ModelAdmin): def reply_count(self, obj): return obj.get_reply_count() - list_display = ('id', 'title', 'reply_count', 'archived') - list_filter = ('bump_time', 'archived') + def ip(self, obj): + return obj.get_opening_post().poster_ip + + list_display = ('id', 'title', 'reply_count', 'archived', 'ip') + list_filter = ('bump_time', 'archived', 'bumpable') search_fields = ('id', 'title') +@admin.register(Ban) class BanAdmin(admin.ModelAdmin): list_display = ('ip', 'can_read') list_filter = ('can_read',) - search_fields = ('ip',) - -admin.site.register(Post, PostAdmin) -admin.site.register(Tag, TagAdmin) -admin.site.register(Ban, BanAdmin) -admin.site.register(Thread, ThreadAdmin) + search_fields = ('ip',) \ No newline at end of file diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -138,10 +138,6 @@ class Thread(models.Model): self.tags.add(tag) tag.threads.add(self) - def remove_tag(self, tag): - self.tags.remove(tag) - tag.threads.remove(self) - def get_opening_post(self, only_id=False): """ Gets the first post of the thread @@ -185,3 +181,11 @@ class Thread(models.Model): def __str__(self): return 'T#{}/{}'.format(self.id, self.get_opening_post_id()) + + def save(self, force_insert=False, force_update=False, using=None, + update_fields=None): + super().save(force_insert, force_update, using, update_fields) + + if not update_fields or 'tags' in update_fields: + for tag in self.tags.all(): + tag.threads.add(self) \ No newline at end of file