admin.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from django.contrib import admin
  2. from scrobbles.models import (
  3. AudioScrobblerTSVImport,
  4. ChartRecord,
  5. KoReaderImport,
  6. LastFmImport,
  7. RetroarchImport,
  8. Scrobble,
  9. )
  10. from scrobbles.mixins import Genre
  11. class ScrobbleInline(admin.TabularInline):
  12. model = Scrobble
  13. extra = 0
  14. raw_id_fields = (
  15. "video",
  16. "podcast_episode",
  17. "track",
  18. "video_game",
  19. "book",
  20. "sport_event",
  21. "board_game",
  22. "geo_location",
  23. "web_page",
  24. "life_event",
  25. "user",
  26. )
  27. exclude = (
  28. "scrobble_log",
  29. "timezone",
  30. "videogame_save_data",
  31. "videogame_screenshot",
  32. )
  33. class ImportBaseAdmin(admin.ModelAdmin):
  34. date_hierarchy = "created"
  35. list_display = (
  36. "uuid",
  37. "process_count",
  38. "processed_finished",
  39. "processing_started",
  40. )
  41. ordering = ("-created",)
  42. @admin.register(AudioScrobblerTSVImport)
  43. class AudioScrobblerTSVImportAdmin(ImportBaseAdmin):
  44. ...
  45. @admin.register(LastFmImport)
  46. class LastFmImportAdmin(ImportBaseAdmin):
  47. ...
  48. @admin.register(KoReaderImport)
  49. class KoReaderImportAdmin(ImportBaseAdmin):
  50. ...
  51. @admin.register(RetroarchImport)
  52. class RetroarchImportAdmin(ImportBaseAdmin):
  53. ...
  54. @admin.register(Genre)
  55. class GenreAdmin(admin.ModelAdmin):
  56. list_display = (
  57. "name",
  58. "source",
  59. )
  60. @admin.register(ChartRecord)
  61. class ChartRecordAdmin(admin.ModelAdmin):
  62. date_hierarchy = "created"
  63. list_display = (
  64. "user",
  65. "rank",
  66. "count",
  67. "year",
  68. "week",
  69. "month",
  70. "day",
  71. "media_name",
  72. )
  73. ordering = ("-created",)
  74. def media_name(self, obj):
  75. return obj.media_obj
  76. @admin.register(Scrobble)
  77. class ScrobbleAdmin(admin.ModelAdmin):
  78. date_hierarchy = "timestamp"
  79. list_display = (
  80. "timestamp",
  81. "media_name",
  82. "media_type",
  83. "playback_percent",
  84. "source",
  85. "in_progress",
  86. "is_paused",
  87. "played_to_completion",
  88. )
  89. raw_id_fields = (
  90. "video",
  91. "podcast_episode",
  92. "track",
  93. "sport_event",
  94. "book",
  95. "video_game",
  96. "board_game",
  97. "geo_location",
  98. "web_page",
  99. "life_event",
  100. )
  101. list_filter = (
  102. "is_paused",
  103. "in_progress",
  104. "media_type",
  105. "long_play_complete",
  106. "source",
  107. )
  108. ordering = ("-timestamp",)
  109. def media_name(self, obj):
  110. return obj.media_obj
  111. def playback_percent(self, obj):
  112. return obj.percent_played