adding
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from django.shortcuts import redirect
|
||||
|
||||
from .models import TermsAndConditions, User
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(BaseUserAdmin):
|
||||
model = User
|
||||
list_display = ("phone", "name", "state", "gem_balance", "referral_code", "is_active", "is_staff", "created_at")
|
||||
list_filter = ("state", "is_active", "is_staff")
|
||||
search_fields = ("phone", "name", "referral_code")
|
||||
ordering = ("-created_at",)
|
||||
readonly_fields = (
|
||||
"otp_code",
|
||||
"otp_expiry",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"last_login",
|
||||
"gem_balance",
|
||||
"referral_code",
|
||||
"referral_bonus_granted",
|
||||
)
|
||||
autocomplete_fields = ["referred_by"]
|
||||
|
||||
fieldsets = (
|
||||
(None, {"fields": ("phone", "password")}),
|
||||
("اطلاعات شخصی", {"fields": ("name",)}),
|
||||
("وضعیت", {"fields": ("state", "is_active", "is_staff", "is_superuser", "groups", "user_permissions")}),
|
||||
(
|
||||
"جم و معرفی",
|
||||
{"fields": ("gem_balance", "trial_expires_at", "referral_code", "referred_by", "referral_bonus_granted")},
|
||||
),
|
||||
("OTP", {"fields": ("otp_code", "otp_expiry")}),
|
||||
("تاریخها", {"fields": ("created_at", "updated_at", "last_login")}),
|
||||
)
|
||||
add_fieldsets = (
|
||||
(None, {"classes": ("wide",), "fields": ("phone", "password1", "password2")}),
|
||||
)
|
||||
|
||||
|
||||
@admin.register(TermsAndConditions)
|
||||
class TermsAndConditionsAdmin(admin.ModelAdmin):
|
||||
"""تکردیفی — لیست را رد میکنیم و مستقیم فرم ویرایش همان یک ردیف را نشان میدهیم."""
|
||||
|
||||
list_display = ("updated_at",)
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return not TermsAndConditions.objects.exists()
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
obj = TermsAndConditions.get_solo()
|
||||
return redirect("admin:account_termsandconditions_change", obj.pk)
|
||||
Reference in New Issue
Block a user