- Admin-only: list contacts, create/edit campaigns and compositions - Public: submit contact, mine contacts by email/phone, read campaigns/compositions - Add admin_response field on ContactUs - Update Postman base_url to https://zoneco.org/api with token save Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
2.7 KiB
Python
88 lines
2.7 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', 'has_admin_response', 'created_at']
|
|
list_filter = ['category', 'created_at']
|
|
search_fields = ['name', 'email_or_phone', 'description', 'admin_response']
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
date_hierarchy = 'created_at'
|
|
|
|
fieldsets = (
|
|
('اطلاعات تماس', {
|
|
'fields': ('name', 'email_or_phone', 'category')
|
|
}),
|
|
('پیام', {
|
|
'fields': ('description',)
|
|
}),
|
|
('پاسخ ادمین', {
|
|
'fields': ('admin_response',)
|
|
}),
|
|
('اطلاعات زمانی', {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
@admin.display(boolean=True, description='پاسخ ادمین')
|
|
def has_admin_response(self, obj):
|
|
return bool(obj.admin_response and obj.admin_response.strip())
|
|
|
|
|
|
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 = 'فعال'
|