60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
|
|
"""
|
||
|
|
Example admin configuration demonstrating django-translatable-fields usage.
|
||
|
|
"""
|
||
|
|
from django.contrib import admin
|
||
|
|
from django_translatable_fields.admin import TranslatableModelAdmin
|
||
|
|
from .models import Product, Category, BlogPost, Company
|
||
|
|
|
||
|
|
|
||
|
|
@admin.register(Product)
|
||
|
|
class ProductAdmin(TranslatableModelAdmin):
|
||
|
|
"""
|
||
|
|
Admin for Product model with translatable fields.
|
||
|
|
"""
|
||
|
|
list_display = ['name', 'slug', 'price', 'created_at']
|
||
|
|
list_filter = ['created_at']
|
||
|
|
search_fields = ['name', 'description']
|
||
|
|
fields = ['name', 'description', 'slug', 'support_email', 'website', 'price']
|
||
|
|
prepopulated_fields = {'slug': ('name',)}
|
||
|
|
|
||
|
|
|
||
|
|
@admin.register(Category)
|
||
|
|
class CategoryAdmin(TranslatableModelAdmin):
|
||
|
|
"""
|
||
|
|
Admin for Category model with translatable fields.
|
||
|
|
"""
|
||
|
|
list_display = ['name', 'slug']
|
||
|
|
search_fields = ['name', 'description']
|
||
|
|
fields = ['name', 'description', 'slug', 'meta_description']
|
||
|
|
prepopulated_fields = {'slug': ('name',)}
|
||
|
|
|
||
|
|
|
||
|
|
@admin.register(BlogPost)
|
||
|
|
class BlogPostAdmin(TranslatableModelAdmin):
|
||
|
|
"""
|
||
|
|
Admin for BlogPost model demonstrating all translatable field types.
|
||
|
|
"""
|
||
|
|
list_display = ['title', 'slug', 'published', 'publish_date', 'created_at']
|
||
|
|
list_filter = ['published', 'publish_date', 'created_at']
|
||
|
|
search_fields = ['title', 'content', 'meta_description']
|
||
|
|
fields = [
|
||
|
|
'title', 'content', 'slug', 'author_email', 'external_link',
|
||
|
|
'meta_description', 'published', 'publish_date'
|
||
|
|
]
|
||
|
|
prepopulated_fields = {'slug': ('title',)}
|
||
|
|
date_hierarchy = 'created_at'
|
||
|
|
|
||
|
|
|
||
|
|
@admin.register(Company)
|
||
|
|
class CompanyAdmin(TranslatableModelAdmin):
|
||
|
|
"""
|
||
|
|
Admin for Company model with comprehensive translatable fields.
|
||
|
|
"""
|
||
|
|
list_display = ['name', 'slug', 'contact_email', 'founded_year', 'is_active']
|
||
|
|
list_filter = ['is_active', 'founded_year']
|
||
|
|
search_fields = ['name', 'description', 'address']
|
||
|
|
fields = [
|
||
|
|
'name', 'description', 'slug', 'contact_email', 'website',
|
||
|
|
'address', 'founded_year', 'employee_count', 'is_active'
|
||
|
|
]
|
||
|
|
prepopulated_fields = {'slug': ('name',)}
|