Files
atabackend/blog/admin.py
Beyhan Oğur d50f14bcb1 first commit
2026-04-26 22:20:45 +03:00

96 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.contrib import admin
from django.utils.safestring import mark_safe
from blog.models import Category, Tags, Post, Comment, CategoryView
# Register your models here.
class PostAdmin(admin.ModelAdmin):
list_display = ('title', 'post_resim', 'is_active', 'post_kategorileri', 'slug')
list_filter = ('is_active', 'categories')
search_fields = ('title', 'is_active', 'slug', 'content')
list_editable = ('is_active', 'slug',) # Removed 'price' as it is not a field
class Meta:
model = Post
def formatted_hit_count(self, obj):
return obj.current_hit_count if obj.current_hit_count > 0 else '-'
formatted_hit_count.admin_order_field = 'hit_count'
formatted_hit_count.short_description = 'Hits'
def post_tags(self, obj):
tags = '<ul>'
for tag in obj.tags.all():
tags += '<li>' + tag.tag + '</li>'
tags += '</ul>'
return mark_safe(tags)
def post_kategorileri(self, obj):
html = '<ul>'
for category in obj.categories.all():
html += '<li>' + category.title + '</li>'
html += '</ul>'
return mark_safe(html)
def post_resim(self, obj):
if obj.image:
return mark_safe(
'<a href="/admin/post/post/{}/change/#id_images" onclick="window.location.href=\'/admin/post/post/{}/change/#id_images\'; return false;"><img src="{}" width="50" height="50" style="object-fit: cover; cursor: pointer;" title="Resmi değiştirmek için tıklayın" /></a>'.format(
obj.id, obj.id, obj.image.url))
return mark_safe(
'<a href="/admin/post/post/{}/change/#id_images" onclick="window.location.href=\'/admin/post/post/{}/change/#id_images\'; return false;">Resim Yok</a>'.format(
obj.id, obj.id))
post_resim.short_description = 'Kurs Resmi'
admin.site.register(Post, PostAdmin)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('title', 'parent_category', 'is_active', 'created_at', 'order') # Removed 'view_count' and 'unique_view_count'
list_filter = ('title', 'is_active', 'created_at', 'parent')
search_fields = ('title', 'is_active', 'slug')
list_editable = ('is_active', 'order')
class Meta:
model = Category
def parent_category(self, obj):
if obj.parent:
return obj.parent.title
return "Ana Kategori"
parent_category.short_description = 'Üst Kategori'
admin.site.register(Category, CategoryAdmin)
class TagsAdmin(admin.ModelAdmin):
list_display = ('tag', 'created_at',)
list_filter = ('tag',)
search_fields = ('tag',)
class Meta:
model = Tags
admin.site.register(Tags, TagsAdmin)
class CategoryViewAdmin(admin.ModelAdmin):
list_display = ('category', 'ip_address', 'created_at')
list_filter = ('created_at', 'category')
search_fields = ('ip_address', 'category__title')
readonly_fields = ('category', 'ip_address', 'user_agent', 'created_at')
class Meta:
model = CategoryView
admin.site.register(CategoryView, CategoryViewAdmin)
admin.site.register(Comment)