A
A
Aliym Altymyshev2020-05-15 00:40:42
Django
Aliym Altymyshev, 2020-05-15 00:40:42

Django 3 how to pull post author?

Hello! I understand that when creating a record in the database, Django saves the author of the record? How can I pull this login? You need to make the CRUD mapping only for the user who created this entry. You need to do a check like {% if request.user == post author %} Then display a div block with CRUD buttons {% endif %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Shatalov, 2020-05-15
@netpastor

You don’t understand it that way, janga itself only keeps a change log, but I don’t recommend pulling out data on it. Easier to properly design the model itself

B
bubaley, 2020-05-15
@bubaley

It's better to add a foreignKey to the entry model that will refer to User.
When saving an entry, get the current user from request.user and save it to the entry object.
And then you will correctly be able to check reqest.user == record.user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question