89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
from .models import (
|
|
FUser, PointTransaction, DailyCheckin,
|
|
TaskDefinition, UserTaskProgress, LevelThreshold, UserLevel,
|
|
Region,
|
|
)
|
|
|
|
|
|
class PointTransactionInline(admin.TabularInline):
|
|
model = PointTransaction
|
|
extra = 0
|
|
fields = ['transaction_type', 'currency_type', 'amount', 'balance_after', 'description', 'created_at']
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
class DailyCheckinInline(admin.TabularInline):
|
|
model = DailyCheckin
|
|
extra = 0
|
|
fields = ['checkin_date', 'created_at']
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
@admin.register(FUser)
|
|
class FUserAdmin(admin.ModelAdmin):
|
|
list_display = ['username', 'email', 'phone_number', 'gender', 'points', 'coins', 'is_active', 'date_joined']
|
|
list_filter = ['gender', 'is_active', 'is_staff']
|
|
search_fields = ['username', 'email', 'phone_number']
|
|
ordering = ['-date_joined']
|
|
inlines = [PointTransactionInline, DailyCheckinInline]
|
|
|
|
|
|
@admin.register(PointTransaction)
|
|
class PointTransactionAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'transaction_type', 'currency_type', 'amount', 'balance_after', 'description', 'created_at']
|
|
list_filter = ['transaction_type', 'currency_type']
|
|
search_fields = ['user__username', 'description']
|
|
ordering = ['-created_at']
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
@admin.register(DailyCheckin)
|
|
class DailyCheckinAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'checkin_date', 'created_at']
|
|
list_filter = ['checkin_date']
|
|
search_fields = ['user__username']
|
|
ordering = ['-checkin_date']
|
|
readonly_fields = ['created_at']
|
|
|
|
|
|
@admin.register(TaskDefinition)
|
|
class TaskDefinitionAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'task_type', 'action_type', 'target_count', 'reward_points', 'reward_coins', 'reward_xp', 'is_active', 'sort_order']
|
|
list_filter = ['task_type', 'action_type', 'is_active']
|
|
search_fields = ['name', 'description']
|
|
list_editable = ['is_active', 'sort_order', 'reward_points', 'reward_coins', 'reward_xp', 'target_count']
|
|
|
|
|
|
@admin.register(UserTaskProgress)
|
|
class UserTaskProgressAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'task', 'current_count', 'is_completed', 'is_claimed', 'period_key', 'updated_at']
|
|
list_filter = ['is_completed', 'is_claimed', 'task__task_type']
|
|
search_fields = ['user__username', 'task__name']
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
|
|
|
|
@admin.register(LevelThreshold)
|
|
class LevelThresholdAdmin(admin.ModelAdmin):
|
|
list_display = ['level', 'title', 'xp_required']
|
|
ordering = ['level']
|
|
list_editable = ['title', 'xp_required']
|
|
|
|
|
|
@admin.register(UserLevel)
|
|
class UserLevelAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'level', 'xp', 'updated_at']
|
|
list_filter = ['level']
|
|
search_fields = ['user__username']
|
|
readonly_fields = ['updated_at']
|
|
|
|
|
|
@admin.register(Region)
|
|
class RegionAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'code', 'level', 'parent', 'pinyin', 'sort_order']
|
|
list_filter = ['level']
|
|
search_fields = ['name', 'code', 'pinyin']
|
|
list_editable = ['sort_order']
|
|
ordering = ['level', 'sort_order', 'code']
|