I have an app called forms_and_models that I use for study. In the Django 1.7 documentation says:
Assuming you have an application whose app_label is foo and a template called Bar , to test basic permissions, you should use:
- to add:
- to change:
- to delete:
Through the admin, I’ve added the permission: forms_and_models | author | Can add author to my user. Following the documentation template, I deduced that to test if a user has permission to add an author, I could run the following code:
"""O usuário abaixo existe e é o que eu configurei a permissão acima"""
user = User.objects.get(username='junior')
However, this line of code always returns false. What am I letting go unnoticed about the permissions system?
I discovered what was happening. The problem was just that I was starting the interactive shell via terminal using Python 3, like this:
python3 manage.py shell
When I opened using the
./manage.py shell command, which uses the shebang of the manage.py file, everything happened as per the documentation. Permissions are now listed normally. I’ve never had problems like this using Python 3 to start the shell. Go understand.