Add: archive app models to django admin

This commit is contained in:
Aroy-Art 2025-03-13 18:55:08 +01:00
parent 25936125e1
commit 4f27933a4b
Signed by: Aroy
GPG key ID: 583642324A1D2070

View file

@ -1,6 +1,8 @@
from django.contrib import admin
from django.utils.dateformat import format
from django.utils.timezone import localtime
from .models import SourceSiteModel
from .models import SourceSiteModel, CreatorModel, DescriptionModel, TagModel, PostModel
class SourceSiteAdmin(admin.ModelAdmin):
@ -8,3 +10,74 @@ class SourceSiteAdmin(admin.ModelAdmin):
admin.site.register(SourceSiteModel, SourceSiteAdmin)
class DescriptionAdmin(admin.ModelAdmin):
list_display = ["hash", "description_at", "date_modified", "date_created"]
def description_at(self, obj):
if len(str(obj.content)) >= 80:
return obj.content[:77] + "..."
else:
return obj.content
description_at.short_description = "Description"
admin.site.register(DescriptionModel, DescriptionAdmin)
class TagAdmin(admin.ModelAdmin):
list_display = ["slug", "name", "date_modified", "date_created"]
admin.site.register(TagModel, TagAdmin)
class CreatorAdmin(admin.ModelAdmin):
list_display = [
"slug",
"name",
"source_site",
"date_created",
"date_last_import",
]
admin.site.register(CreatorModel, CreatorAdmin)
class PostAdmin(admin.ModelAdmin):
list_display = [
"post_id",
"source_site",
"creator",
"title",
"description_at",
"mature",
"date_created_fromated",
"date_imported_formated",
"date_last_import_formated",
]
@admin.display(description="Description")
def description_at(self, obj):
if len(str(obj.description.first().content)) >= 80:
return obj.description.first().content[:77] + "..."
else:
return obj.description.first().content
@admin.display(description="Date Created")
def date_created_fromated(self, obj):
return format(localtime(obj.date_created), "Y-m-d H:i:s")
@admin.display(description="Date Imported")
def date_imported_formated(self, obj):
return format(localtime(obj.date_imported), "Y-m-d H:i:s")
@admin.display(description="Last Import Date")
def date_last_import_formated(self, obj):
return format(localtime(obj.date_last_import), "Y-m-d H:i:s")
admin.site.register(PostModel, PostAdmin)