12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- from admin_auto_filters.filters import AutocompleteFilterFactory
- from django.utils.translation import gettext_lazy as _
- from django.contrib import admin
- from .models import Genre, Author, Collection, Metric, Book, UsersBooksCollections
- @admin.register(Genre)
- class GenreAdmin(admin.ModelAdmin):
- list_display = ("title", "created_at", "updated_at")
- list_filter = ("created_at", "updated_at")
- search_fields = ("title",)
- date_hierarchy = "created_at"
- ordering = ("-created_at",)
- readonly_fields = ("created_at", "updated_at")
- @admin.register(Author)
- class AuthorAdmin(admin.ModelAdmin):
- list_display = ("name", "avatar", "created_at", "updated_at")
- list_filter = ("created_at", "updated_at")
- search_fields = ("name",)
- date_hierarchy = "created_at"
- ordering = ("-created_at",)
- readonly_fields = ("created_at", "updated_at")
- @admin.register(Collection)
- class CollectionAdmin(admin.ModelAdmin):
- list_display = ("title", "created_at", "updated_at")
- list_filter = ("created_at", "updated_at")
- search_fields = ("title",)
- date_hierarchy = "created_at"
- ordering = ("-created_at",)
- readonly_fields = ("created_at", "updated_at")
- @admin.register(Metric)
- class MetricAdmin(admin.ModelAdmin):
- list_display = ("user", "pages_read", "reading_time", "books_read", "created_at", "updated_at")
- list_filter = ("created_at", "updated_at")
- search_fields = ("user",)
- date_hierarchy = "created_at"
- ordering = ("-created_at",)
- autocomplete_fields = ("user",)
- readonly_fields = ("created_at", "updated_at")
- @admin.register(Book)
- class PostAdmin(admin.ModelAdmin):
- list_display = ("title", "annotation", "symbols_count", "book_file", "pages_count", "is_recognized", "cover", "is_private", "created_at", "updated_at")
- list_filter = ("is_private", "genres", "authors", "created_at", "updated_at")
- search_fields = ("title", "annotation")
- date_hierarchy = "created_at"
- ordering = ("title","-created_at",)
- autocomplete_fields = ("genres", "authors")
- readonly_fields = ("created_at", "updated_at")
- @admin.register(UsersBooksCollections)
- class UsersBooksCollectionsAdmin(admin.ModelAdmin):
- list_display = ("user", "book", "collection", "current_page", "created_at", "updated_at")
- list_filter = ("collection", "created_at", "updated_at")
- search_fields = ("user", "book", "title", "annotation")
- date_hierarchy = "created_at"
- ordering = ("-created_at",)
- autocomplete_fields = ("user", "book", "collection")
- readonly_fields = ("created_at", "updated_at")
|