Matching vars in template doesn't work as intended|datatype problem ?

Hi there, i try to configure some templates of a Django-project to display some Buttons only if certain conditions are true.

At the moment i am stuck at the following:

{% if request.user == entry.employee_number %}

The characters of both values are identical, but result of comparison shows “false”.
So could it be caused by the datatypes ? the data type of employee_number is CharField.
As you can use every character for username, i think this also must be CharField…

What am I missing ?

request.user is not a character field, and it’s not the username, it’s a reference to an object. Hopefully, employee_number is a field in the User object, in which case your test would be:

{% if request.user.employee_number == entry.employee_number %}

What you see as the output of a print statement, or from rendering something like {{ request.user }}, is not the contents of the object itself. It’s intended to be a readable representation of that object.

Hi once more, Ken,

I understand Your description. No, employee_number is not a field of User .
And you were saying, that a matching print statement is not helpful. Up to now, I tried it only with a verification about this mentioned print statement, which results in identical values for both. So if this is not the way (obviously) to resolve this problem…what could I do if employee_number is from a model of Django app and request.user is the representation for the logged in user ? Is there a way tho force the if statement to compare both values in a way that would work ?

If this would be better, i could also do comparison in the views.py …but how?

You said that employee_number is a CharField. What field in the user object are you looking to match it with? That would be the field name you use in the if tag.

Never mind, i was able to solve this on my own…
with THIS
request.user.username == entry.employee_number
it works as intended

Im curious and I hope it is ok to ask. Why would usernames be numbers? Is it really?