# -*- coding: utf-8 -*-

from django.contrib import admin
from django_admin import ChangeOnlyModelAdmin, ReadOnlyModelAdmin

from account.models import UserInfo
from mch.models import ConsumeInfoSubmitLogInfo


class UserInfoAdmin(admin.ModelAdmin):
    list_display = ('brand_id', 'user_id', 'nickname', 'phone', 'unionid', 'openid', 'openid_miniapp', 'location', 'balance', 'user_status', 'test_user', 'status', 'created_at', 'updated_at')
    list_filter = ('brand_id', 'test_user', 'sex', 'user_status', 'status')
    readonly_fields = ('user_id', )
    search_fields = ('user_id', 'username', 'unionid', 'openid', 'openid_miniapp', 'nickname', 'name', 'phone', 'location')

    def save_model(self, request, obj, form, change):
        obj.save()
        if obj.test_user:
            ConsumeInfoSubmitLogInfo.objects.filter(user_id=obj.user_id).update(test_user=True)


admin.site.register(UserInfo, UserInfoAdmin)
