admin.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. "task",
  24. "mood",
  25. "brickset",
  26. "trail",
  27. "beer",
  28. "web_page",
  29. "life_event",
  30. "user",
  31. )
  32. exclude = (
  33. "scrobble_log",
  34. "timezone",
  35. "videogame_save_data",
  36. "screenshot",
  37. )
  38. class ImportBaseAdmin(admin.ModelAdmin):
  39. date_hierarchy = "created"
  40. list_display = (
  41. "uuid",
  42. "process_count",
  43. "processed_finished",
  44. "processing_started",
  45. )
  46. ordering = ("-created",)
  47. @admin.register(AudioScrobblerTSVImport)
  48. class AudioScrobblerTSVImportAdmin(ImportBaseAdmin):
  49. ...
  50. @admin.register(LastFmImport)
  51. class LastFmImportAdmin(ImportBaseAdmin):
  52. ...
  53. @admin.register(KoReaderImport)
  54. class KoReaderImportAdmin(ImportBaseAdmin):
  55. ...
  56. @admin.register(RetroarchImport)
  57. class RetroarchImportAdmin(ImportBaseAdmin):
  58. ...
  59. @admin.register(Genre)
  60. class GenreAdmin(admin.ModelAdmin):
  61. list_display = (
  62. "name",
  63. "source",
  64. )
  65. @admin.register(ChartRecord)
  66. class ChartRecordAdmin(admin.ModelAdmin):
  67. date_hierarchy = "created"
  68. list_display = (
  69. "user",
  70. "rank",
  71. "count",
  72. "year",
  73. "week",
  74. "month",
  75. "day",
  76. "media_name",
  77. )
  78. ordering = ("-created",)
  79. def media_name(self, obj):
  80. return obj.media_obj
  81. @admin.register(Scrobble)
  82. class ScrobbleAdmin(admin.ModelAdmin):
  83. # date_hierarchy = "timestamp"
  84. list_display = (
  85. "timestamp",
  86. "media_name",
  87. "media_type",
  88. "playback_percent",
  89. "source",
  90. "in_progress",
  91. "is_paused",
  92. "played_to_completion",
  93. )
  94. raw_id_fields = (
  95. "video",
  96. "podcast_episode",
  97. "track",
  98. "sport_event",
  99. "book",
  100. "video_game",
  101. "board_game",
  102. "geo_location",
  103. "task",
  104. "mood",
  105. "brickset",
  106. "trail",
  107. "beer",
  108. "web_page",
  109. "life_event",
  110. )
  111. list_filter = (
  112. "is_paused",
  113. "in_progress",
  114. "media_type",
  115. "long_play_complete",
  116. "source",
  117. )
  118. ordering = ("-timestamp",)
  119. def media_name(self, obj):
  120. return obj.media_obj
  121. def playback_percent(self, obj):
  122. return obj.percent_played