- Add CompositionImage model with multi-image upload and main image flag - Add composition endpoints: add-images, set-main-image, delete image, by-created-at filter - Make contact-us by_category public - Add 24 API tests covering all endpoints - Add Dockerfile, docker-compose, entrypoint and docker docs - Add Persian API docs and update README and Postman collection Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from django.contrib import admin
|
|
from .models import ContactUs, Composition, Campaign, CompositionImage
|
|
|
|
|
|
@admin.register(ContactUs)
|
|
class ContactUsAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'email_or_phone', 'category', 'created_at']
|
|
list_filter = ['category', 'created_at']
|
|
search_fields = ['name', 'email_or_phone', 'description']
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
date_hierarchy = 'created_at'
|
|
|
|
fieldsets = (
|
|
('اطلاعات تماس', {
|
|
'fields': ('name', 'email_or_phone', 'category')
|
|
}),
|
|
('پیام', {
|
|
'fields': ('description',)
|
|
}),
|
|
('اطلاعات زمانی', {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
class CompositionImageInline(admin.TabularInline):
|
|
model = CompositionImage
|
|
extra = 1
|
|
fields = ['image', 'is_main', 'created_at']
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
@admin.register(Composition)
|
|
class CompositionAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'created_at']
|
|
search_fields = ['name', 'description']
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
date_hierarchy = 'created_at'
|
|
inlines = [CompositionImageInline]
|
|
|
|
fieldsets = (
|
|
('اطلاعات ترکیب', {
|
|
'fields': ('name', 'description', 'image')
|
|
}),
|
|
('اطلاعات زمانی', {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
@admin.register(Campaign)
|
|
class CampaignAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'start_time', 'end_time', 'is_active', 'created_at']
|
|
list_filter = ['start_time', 'end_time', 'created_at']
|
|
search_fields = ['name', 'description']
|
|
readonly_fields = ['created_at', 'updated_at', 'is_active']
|
|
date_hierarchy = 'start_time'
|
|
|
|
fieldsets = (
|
|
('اطلاعات کمپین', {
|
|
'fields': ('name', 'description', 'image')
|
|
}),
|
|
('زمانبندی', {
|
|
'fields': ('start_time', 'end_time')
|
|
}),
|
|
('وضعیت', {
|
|
'fields': ('is_active',)
|
|
}),
|
|
('اطلاعات زمانی', {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
def is_active(self, obj):
|
|
return obj.is_active()
|
|
is_active.boolean = True
|
|
is_active.short_description = 'فعال'
|