D
D
Dmitry Vyatkin2016-02-24 23:40:36
Django
Dmitry Vyatkin, 2016-02-24 23:40:36

How in django to allow editing only your entries in the model?

Good evening! I need to allow users to edit, delete and add only their entries in the model. If I understand correctly, then the standard access rights apply to all data in the model. Are decorators suitable for these purposes and where to define them in generic views. I know that the question was raised, but please tell me where to dig!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
X
xozzslip, 2016-02-25
@xozzslip

You can do this: add a field to the model owner = models.ForeignKey(User), then check in the viewowner == request.user

S
sim3x, 2016-02-24
@sim3x

In the model in the CustomManager you check the rights
And / or when you save
the PS, I mean that the model already has the owner fieldcreator = ForeignKey(settings.AUTH_USER_MODEL)

S
Sergey Gornostaev, 2016-02-25
@sergey-gornostaev

django-guardian

D
Dmitry Entelis, 2014-11-19
@abler98

It's not very clear what error you get if there are no matches.
Your function should just return false as far as the code makes sense.
PS It makes sense to make a separate select count query only when, for example, you need to get the number of results without getting the results themselves.

F
FanatPHP, 2014-11-19
@FanatPHP

Here you can really throw out a bunch of meaningless code.

$sql = "SELECT ...";
return $this->database->query($sql)->fetch_assoc();

is ALL the code you need.
If there are no matches, neither this code nor the code given in the request will generate any error. The author got confused.
And the problem, rather, is not in coincidences, but in the absence of initial data and the inability to correctly add data to the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question