123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- import monetary
- from django.conf import settings
- from django.contrib import admin
- from django.contrib.auth.hashers import make_password
- from django_admin import ReadOnlyModelAdmin
- from django_models_ext import ProvinceShortModelMixin
- from pysnippets.strsnippets import strip
- from mch.models import (AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, LatestAppInfo,
- LatestAppScreenInfo, ModelInfo, OperatorInfo, SaleclerkInfo)
- class AdministratorInfoAdmin(admin.ModelAdmin):
- list_display = ('admin_id', 'phone', 'password', 'encryption', 'name', 'brand_id', 'brand_name', 'user_status', 'status', 'created_at', 'updated_at')
- list_filter = ('user_status', 'status', 'brand_name')
- readonly_fields = ('encryption', 'brand_name')
- def save_model(self, request, obj, form, change):
- obj.phone = strip(obj.phone)
- obj.password = strip(obj.password)
- if obj.password:
- obj.encryption = make_password(obj.password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER)
- obj.password = ''
- obj.brand_id = strip(obj.brand_id)
- try:
- obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
- except BrandInfo.DoesNotExist:
- obj.brand_name = ''
- obj.save()
- class OperatorInfoAdmin(admin.ModelAdmin):
- list_display = ('operator_id', 'phone', 'password', 'encryption', 'name', 'brand_id', 'brand_name', 'brand_domain', 'user_status', 'status', 'created_at', 'updated_at')
- list_filter = ('user_status', 'status', 'brand_name')
- readonly_fields = ('brand_domain', 'encryption', 'brand_name')
- def save_model(self, request, obj, form, change):
- obj.phone = strip(obj.phone)
- obj.password = strip(obj.password)
- if obj.password:
- obj.encryption = make_password(obj.password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER)
- obj.password = ''
- obj.brand_id = strip(obj.brand_id)
- try:
- obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
- except BrandInfo.DoesNotExist:
- obj.brand_name = ''
- obj.save()
- class BrandInfoAdmin(admin.ModelAdmin):
- list_display = ('brand_id', 'brand_name', 'brand_descr', 'brand_logo', 'brand_domain', 'position', 'status', 'created_at', 'updated_at')
- def save_model(self, request, obj, form, change):
- obj.save()
- OperatorInfo.objects.filter(brand_id=obj.brand_id).update(brand_domain=obj.brand_domain)
- class ModelInfoAdmin(admin.ModelAdmin):
- list_display = ('brand_id', 'brand_name', 'jancode', 'model_id', 'model_uni_name', 'model_name', 'model_full_name', 'model_descr', 'category', 'warehouse', 'image', 'url', 'factory_yuan', 'integral', 'position', 'display', 'status', 'created_at', 'updated_at')
- list_filter = ('brand_name', 'category', 'warehouse', 'display', 'status')
- readonly_fields = ('brand_name', 'factory_fee')
- search_fields = ('brand_id', 'brand_name', 'jancode', 'model_id', 'model_uni_name', 'model_name', 'model_full_name', 'model_descr', 'category', 'warehouse')
- def save_model(self, request, obj, form, change):
- obj.brand_id = strip(obj.brand_id)
- try:
- obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
- except BrandInfo.DoesNotExist:
- obj.brand_name = ''
- obj.factory_fee = monetary.Yuan2Fen(obj.factory_yuan)
- obj.factory_yuan = monetary.Fen2Yuan(obj.factory_fee)
- obj.save()
- class ModelImageInfoAdmin(admin.ModelAdmin):
- list_display = ('model_id', 'model_name', 'image', 'url', 'position', 'status', 'created_at', 'updated_at')
- list_filter = ('model_name', 'status')
- def save_model(self, request, obj, form, change):
- obj.model_id = strip(obj.model_id)
- try:
- obj.model_name = ModelInfo.objects.get(model_id=obj.model_id).model_name
- except BrandInfo.DoesNotExist:
- obj.model_name = ''
- obj.save()
- class DistributorInfoAdmin(admin.ModelAdmin):
- list_display = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'distributor_short_name', 'distributor_province_name', 'position', 'status', 'created_at', 'updated_at')
- list_filter = ('brand_name', 'distributor_province_name', 'status')
- readonly_fields = ('brand_name', 'distributor_province_code')
- search_fields = ('brand_id', 'brand_name', 'distributor_name', 'distributor_short_name', 'distributor_descr', 'distributor_province_code', 'distributor_province_name')
- def save_model(self, request, obj, form, change):
- obj.brand_id = strip(obj.brand_id)
- try:
- obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
- except BrandInfo.DoesNotExist:
- obj.brand_name = ''
- obj.distributor_province_code = ProvinceShortModelMixin.PROVINCE_NAME_CODE_DICT.get(obj.distributor_province_name, '')
- obj.save()
- class SaleclerkInfoAdmin(admin.ModelAdmin):
- list_display = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'clerk_id', 'clerk_name', 'clerk_sex', 'clerk_phone', 'unionid', 'openid', 'integral', 'total_integral', 'user_status', 'test_user', 'status', 'created_at', 'updated_at')
- list_filter = ('test_user', 'user_status', 'status')
- search_fields = ('brand_id', 'brand_name', 'distributor_id', 'distributor_name', 'clerk_id', 'clerk_name', 'clerk_phone')
-
-
-
-
-
-
- class BrandModelDistributorPriceInfoAdmin(admin.ModelAdmin):
- list_display = ('brand_id', 'brand_name', 'model_id', 'model_name', 'distributor_id', 'distributor_name', 'factory_yuan', 'integral', 'status', 'created_at', 'updated_at')
- list_filter = ('brand_name', 'model_name', 'distributor_name', 'status')
- readonly_fields = ('brand_name', 'model_name', 'distributor_name', 'factory_fee', )
- search_fields = ('brand_id', 'brand_name', 'model_id', 'model_name', 'distributor_id', 'distributor_name')
- def save_model(self, request, obj, form, change):
- obj.brand_id = strip(obj.brand_id)
- try:
- obj.brand_name = BrandInfo.objects.get(brand_id=obj.brand_id).brand_name
- except BrandInfo.DoesNotExist:
- obj.brand_name = ''
- obj.model_id = strip(obj.model_id)
- try:
- obj.model_name = ModelInfo.objects.get(model_id=obj.model_id).model_name
- except BrandInfo.DoesNotExist:
- obj.model_name = ''
- obj.distributor_id = strip(obj.distributor_id)
- try:
- obj.distributor_name = DistributorInfo.objects.get(distributor_id=obj.distributor_id).distributor_name
- except BrandInfo.DoesNotExist:
- obj.distributor_name = ''
- obj.factory_fee = monetary.Yuan2Fen(obj.factory_yuan)
- obj.factory_yuan = monetary.Fen2Yuan(obj.factory_fee)
- obj.save()
- class LatestAppInfoAdmin(admin.ModelAdmin):
- list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'status', 'created_at', 'updated_at')
- list_filter = ('status', )
- readonly_fields = ('status', )
- def save_model(self, request, obj, form, change):
- if not obj.pk and LatestAppInfo.objects.filter(status=True).exists():
- return
- obj.latest_adr_version_name = strip(obj.latest_adr_version_name)
- obj.latest_adr_app = strip(obj.latest_adr_app)
- obj.latest_adr_url = strip(obj.latest_adr_url)
- obj.save()
- class LatestAppScreenInfoAdmin(admin.ModelAdmin):
- list_display = ('latest_adr_version_code', 'latest_adr_version_name', 'latest_adr_app', 'latest_adr_url', 'status', 'created_at', 'updated_at')
- list_filter = ('status', )
- readonly_fields = ('status', )
- def save_model(self, request, obj, form, change):
- if not obj.pk and LatestAppInfo.objects.filter(status=True).exists():
- return
- obj.latest_adr_version_name = strip(obj.latest_adr_version_name)
- obj.latest_adr_app = strip(obj.latest_adr_app)
- obj.latest_adr_url = strip(obj.latest_adr_url)
- obj.save()
- class ConsumeInfoSubmitLogInfoAdmin(ReadOnlyModelAdmin, admin.ModelAdmin):
- list_display = ('user_id', 'phone', 'lat', 'lon', 'serialNo', 'verifyResult', 'test_user', 'status', 'created_at', 'updated_at')
- list_filter = ('test_user', 'verifyResult', 'status')
- admin.site.register(AdministratorInfo, AdministratorInfoAdmin)
- admin.site.register(OperatorInfo, OperatorInfoAdmin)
- admin.site.register(BrandInfo, BrandInfoAdmin)
- admin.site.register(ModelInfo, ModelInfoAdmin)
- admin.site.register(DistributorInfo, DistributorInfoAdmin)
- admin.site.register(SaleclerkInfo, SaleclerkInfoAdmin)
- admin.site.register(LatestAppInfo, LatestAppInfoAdmin)
- admin.site.register(LatestAppScreenInfo, LatestAppScreenInfoAdmin)
- admin.site.register(ConsumeInfoSubmitLogInfo, ConsumeInfoSubmitLogInfoAdmin)
|