admin.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from admin_auto_filters.filters import AutocompleteFilterFactory
  2. from django.utils.translation import gettext_lazy as _
  3. from django.contrib import admin
  4. from .models import Genre, Author, Collection, Metric, Book, UsersBooksCollections
  5. @admin.register(Genre)
  6. class GenreAdmin(admin.ModelAdmin):
  7. list_display = ("title", "created_at", "updated_at")
  8. list_filter = ("created_at", "updated_at")
  9. search_fields = ("title",)
  10. date_hierarchy = "created_at"
  11. ordering = ("-created_at",)
  12. readonly_fields = ("created_at", "updated_at")
  13. @admin.register(Author)
  14. class AuthorAdmin(admin.ModelAdmin):
  15. list_display = ("name", "avatar", "created_at", "updated_at")
  16. list_filter = ("created_at", "updated_at")
  17. search_fields = ("name",)
  18. date_hierarchy = "created_at"
  19. ordering = ("-created_at",)
  20. readonly_fields = ("created_at", "updated_at")
  21. @admin.register(Collection)
  22. class CollectionAdmin(admin.ModelAdmin):
  23. list_display = ("title", "created_at", "updated_at")
  24. list_filter = ("created_at", "updated_at")
  25. search_fields = ("title",)
  26. date_hierarchy = "created_at"
  27. ordering = ("-created_at",)
  28. readonly_fields = ("created_at", "updated_at")
  29. @admin.register(Metric)
  30. class MetricAdmin(admin.ModelAdmin):
  31. list_display = ("user", "pages_read", "reading_time", "books_read", "created_at", "updated_at")
  32. list_filter = ("created_at", "updated_at")
  33. search_fields = ("user",)
  34. date_hierarchy = "created_at"
  35. ordering = ("-created_at",)
  36. autocomplete_fields = ("user",)
  37. readonly_fields = ("created_at", "updated_at")
  38. @admin.register(Book)
  39. class PostAdmin(admin.ModelAdmin):
  40. list_display = ("title", "annotation", "symbols_count", "book_file", "pages_count", "is_recognized", "cover", "is_private", "created_at", "updated_at")
  41. list_filter = ("is_private", "genres", "authors", "created_at", "updated_at")
  42. search_fields = ("title", "annotation")
  43. date_hierarchy = "created_at"
  44. ordering = ("title","-created_at",)
  45. autocomplete_fields = ("genres", "authors")
  46. readonly_fields = ("created_at", "updated_at")
  47. @admin.register(UsersBooksCollections)
  48. class UsersBooksCollectionsAdmin(admin.ModelAdmin):
  49. list_display = ("user", "book", "collection", "current_page", "created_at", "updated_at")
  50. list_filter = ("collection", "created_at", "updated_at")
  51. search_fields = ("user", "book", "title", "annotation")
  52. date_hierarchy = "created_at"
  53. ordering = ("-created_at",)
  54. autocomplete_fields = ("user", "book", "collection")
  55. readonly_fields = ("created_at", "updated_at")