mediacms/files/admin.py

105 lines
2.8 KiB
Python
Raw Normal View History

2020-12-15 22:33:43 +01:00
from django.contrib import admin
from .models import (
Category,
Comment,
2021-05-26 17:35:21 +02:00
EncodeProfile,
Encoding,
2020-12-15 22:33:43 +01:00
Language,
2021-05-26 17:35:21 +02:00
Media,
2020-12-15 22:33:43 +01:00
Subtitle,
2021-05-26 17:35:21 +02:00
Tag,
2020-12-15 22:33:43 +01:00
)
class CommentAdmin(admin.ModelAdmin):
search_fields = ["text"]
list_display = ["text", "add_date", "user", "media"]
ordering = ("-add_date",)
readonly_fields = ("user", "media", "parent")
class MediaAdmin(admin.ModelAdmin):
search_fields = ["title"]
list_display = [
"title",
"user",
"add_date",
"media_type",
"duration",
"state",
"is_reviewed",
"encoding_status",
"featured",
"get_comments_count",
]
list_filter = ["state", "is_reviewed", "encoding_status", "featured", "category"]
ordering = ("-add_date",)
readonly_fields = ("user", "tags", "category", "channel")
def get_comments_count(self, obj):
return obj.comments.count()
@admin.action(description="Generate missing encoding(s)", permissions=["change"])
def generate_missing_encodings(modeladmin, request, queryset):
for m in queryset:
m.encode(force=False)
actions = [generate_missing_encodings]
2020-12-15 22:33:43 +01:00
get_comments_count.short_description = "Comments count"
class CategoryAdmin(admin.ModelAdmin):
search_fields = ["title"]
list_display = ["title", "user", "add_date", "is_global", "media_count"]
list_filter = ["is_global"]
ordering = ("-add_date",)
readonly_fields = ("user", "media_count")
class TagAdmin(admin.ModelAdmin):
search_fields = ["title"]
list_display = ["title", "user", "media_count"]
readonly_fields = ("user", "media_count")
class EncodeProfileAdmin(admin.ModelAdmin):
list_display = ("name", "extension", "resolution", "codec", "description", "active")
list_filter = ["extension", "resolution", "codec", "active"]
search_fields = ["name", "extension", "resolution", "codec", "description"]
list_per_page = 100
fields = ("name", "extension", "resolution", "codec", "description", "active")
class LanguageAdmin(admin.ModelAdmin):
pass
class SubtitleAdmin(admin.ModelAdmin):
pass
class EncodingAdmin(admin.ModelAdmin):
list_display = ["get_title", "chunk", "profile", "progress", "status", "has_file"]
list_filter = ["chunk", "profile", "status"]
def get_title(self, obj):
return str(obj)
get_title.short_description = "Encoding"
def has_file(self, obj):
return obj.media_encoding_url is not None
has_file.short_description = "Has file"
2020-12-15 22:33:43 +01:00
admin.site.register(EncodeProfile, EncodeProfileAdmin)
admin.site.register(Comment, CommentAdmin)
admin.site.register(Media, MediaAdmin)
admin.site.register(Encoding, EncodingAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Subtitle, SubtitleAdmin)
admin.site.register(Language, LanguageAdmin)