# -*- 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(ChangeOnlyModelAdmin, admin.ModelAdmin):
    list_display = ('user_id', 'username', 'unionid', 'openid', 'openid_miniapp', 'name', 'sex', 'nickname', 'phone', 'location', 'balance', 'user_status', 'test_user', 'status', 'created_at', 'updated_at')
    list_filter = ('test_user', 'sex', 'user_status', 'status')
    readonly_fields = ('user_id', )
    search_fields = ('user_id', '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)
