diff --git a/polls/views/__pycache__/media.cpython-39.pyc b/polls/views/__pycache__/media.cpython-39.pyc index 3ee044e..9208f58 100644 Binary files a/polls/views/__pycache__/media.cpython-39.pyc and b/polls/views/__pycache__/media.cpython-39.pyc differ diff --git a/polls/views/media.py b/polls/views/media.py index 2bfcf04..486cfda 100644 --- a/polls/views/media.py +++ b/polls/views/media.py @@ -329,14 +329,11 @@ def media_admin_change(request): if o.is_direct(): # 如果是省直 obj, created = UserModel.objects.get_or_create( - username=phone, last_login=datetime.now()) - if created: - p = Userprofile.objects.create( - user=obj, name=name, organization=o, admin_status=2) - else: - p = Userprofile.objects.filter(user=obj).first() - p.admin_status = 2 - p.save() + username=phone) + if not created: + return JsonResponse({'status': 'error', 'message': '手机号已存在'}) + p = Userprofile.objects.create( + user=obj, name=name, organization=o, admin_status=2) profile.admin_status = 5 profile.save() managers = Userprofile.level1_admin() @@ -350,14 +347,11 @@ def media_admin_change(request): return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}}) else: obj, created = UserModel.objects.get_or_create( - username=phone, last_login=datetime.now()) - if created: - p = Userprofile.objects.create( - user=obj, name=name, organization=o, admin_status=1) - else: - p = Userprofile.objects.filter(user=obj).first() - p.admin_status = 2 - p.save() + username=phone) + if not created: + return JsonResponse({'status': 'error', 'message': '手机号已存在'}) + p = Userprofile.objects.create( + user=obj, name=name, organization=o, admin_status=1) profile.admin_status = 4 profile.save() managers = Userprofile.level2_admin(o.cities)