Менеджер не доступен через инстанцию Police
Возникает ошибка if user.objects.filter(login_id=login_obj).exists(): как решить эту ошибку
Это мой police_app/views.py
def police_register(request):
if request.method == 'POST':
login_obj = Login()
login_obj.username = request.POST.get('uname')
login_obj.password = request.POST.get('pwd')
login_obj.save()
if Login.objects.filter(username=request.POST.get('uname')).exists():
user = Police()
user.station_name = request.POST.get('name')
user.email = request.POST.get('email')
user.mobile = request.POST.get('mob')
user.district = request.POST.get('district')
user.state = request.POST.get('state')
user.login_id = login_obj
user.save()
if user.objects.filter(login_id=login_obj).exists():
return render(request, "login.html")
return render(request, "police_app/police_register.html", context={'error': 'Registration failed'})
return render(request, "police_app/police_register.html")
Пояснение
Менеджер недоступен через экземпляры полиции
Это уже объясняет причину ошибки. Вы пытались вызвать менеджер модели через экземпляр, что не допустимо. Вместо этого вы должны обращаться к менеджеру через класс модели.
Решение
Change
if user.objects.filter(login_id=login_obj).exists():
...
to
if Police.objects.filter(login_id=login_obj).exists():
...