K
K
Kirill2020-04-16 10:39:16
Django
Kirill, 2020-04-16 10:39:16

Why doesn't the Django database record existence check work?

I need to check who the user is when entering the personal account. The code below is not working, please tell me why? All entries are in the database. Moreover, if instead of username_temp I enter a specific phone number in the code, then it will work and display my role in context.

def lk_point(request):
    context = {}
    username_temp = request.user.get_username
    context['username'] = username_temp
    if point.objects.filter(telephone=username_temp).exists():
        context['info'] = "Вы - пункт"
    elif client.objects.filter(telephone=username_temp).exists():
        context['info'] = "Вы - клиент"
    return render(request, 'lk_point.html', context)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan Krapivin, 2020-04-16
@kustiktm_kirill

probably because request.user.get_usernamethis is a method, not a field with a value, and it must be called
add brackets to call the method that will return the username
username_temp = request.user.get_username()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question