Answer the question
In order to leave comments, you need to log in
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
You can do this: add a field to the model owner = models.ForeignKey(User)
, then check in the viewowner == request.user
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)
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.
Here you can really throw out a bunch of meaningless code.
$sql = "SELECT ...";
return $this->database->query($sql)->fetch_assoc();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question