admin.py
45 lines
| 1.2 KiB
| text/x-python
|
PythonLexer
/ boards / admin.py
|
r0 | from django.contrib import admin | |
|
r728 | from boards.models import Post, Tag, Ban, Thread | |
|
r0 | ||
|
r333 | ||
|
r906 | @admin.register(Post) | |
|
r305 | class PostAdmin(admin.ModelAdmin): | |
list_display = ('id', 'title', 'text') | |||
|
r398 | list_filter = ('pub_time', 'thread_new') | |
|
r305 | search_fields = ('id', 'title', 'text') | |
|
r906 | exclude = ('referenced_posts', 'refmap') | |
readonly_fields = ('poster_ip', 'thread_new') | |||
|
r305 | ||
|
r333 | ||
|
r906 | @admin.register(Tag) | |
|
r305 | class TagAdmin(admin.ModelAdmin): | |
|
r910 | def thread_count(self, obj: Tag) -> int: | |
return obj.get_thread_count() | |||
list_display = ('name', 'thread_count') | |||
|
r906 | search_fields = ('name',) | |
|
r305 | ||
|
r883 | ||
|
r906 | @admin.register(Thread) | |
|
r604 | class ThreadAdmin(admin.ModelAdmin): | |
|
r910 | def title(self, obj: Thread) -> str: | |
|
r883 | return obj.get_opening_post().get_title() | |
|
r604 | ||
|
r910 | def reply_count(self, obj: Thread) -> int: | |
|
r604 | return obj.get_reply_count() | |
|
r910 | def ip(self, obj: Thread): | |
|
r906 | return obj.get_opening_post().poster_ip | |
list_display = ('id', 'title', 'reply_count', 'archived', 'ip') | |||
list_filter = ('bump_time', 'archived', 'bumpable') | |||
|
r604 | search_fields = ('id', 'title') | |
|
r883 | ||
|
r906 | @admin.register(Ban) | |
|
r804 | class BanAdmin(admin.ModelAdmin): | |
list_display = ('ip', 'can_read') | |||
list_filter = ('can_read',) | |||
|
r906 | search_fields = ('ip',) |