S
S
Socrates2018-02-06 18:12:05
Django
Socrates, 2018-02-06 18:12:05

Check the user to which model is he associated?

What is:
two different users, the user can register as one type or as the second. (customer / executor)
in contecst_processers I want to check what type the user belongs to,
I do this:

def getting_user_type(request):
    if (User.objects.filter(email=request.user)):
        current_user = request.user
        current_user_in_User = User.objects.get(email=current_user)

        if current_user_in_User.CustomerProfile:
            userTypeCustomer = True
        else:
            userTypePrinting = True
    else:
        print("ne ok")
    return locals()

but when checking if current_user_in_User.CustomerProfile:
if the CustomerProfile model is not attached to the current user, then I expected that the check would jump to else and everything would be fine.
But an error occurs that the user does not have a CustomerProfile model, if the user (executor), if this is a customer, then everything works as it should.
How to do a normal check here?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question