There are users in the admin, they are given the right to add and edit materials. However, when a user who has these rights goes into the materials, he sees all the materials there, both his own and others'.

How to make so that each user saw only the materials, those which he added? Consequently, he could edit too, only his own. (where such a filter is prescribed in order to influence the admin panel?)

The table of materials has a field user_id (Foreign Keys - User) , that is, each material knows who created it.

    3 answers 3

    You need to look towards the ModelAdmin class queryset method:

     class MyModelAdmin(admin.ModelAdmin): def queryset(self, request): qs = super(MyModelAdmin, self).queryset(request) if request.user.is_superuser: return qs return qs.filter(author=request.user) 

    ModelAdmin.queryset

      I don’t know for sure, but, in my opinion, this out-of-the-box filter is not provided, but it’s easy to write one. Here is a good example of how to do this.

      • You can try, if it does not work out this way, I will suggest how to do @qnub. - trec

      There's no such thing. Admin in django is something like root in * nix - you should not let moderators / managers and other service people into it, for them you need to write your own, higher-level interfaces that will take into account all the business logic of the application.

      • There's something about it. However, a little disagree. In the admin there is an opportunity to make users moderators, and there is an opportunity to create groups, distribute rights there and there, it means the creators were guided by the fact that all such actions will be carried out in a standard admin area. It is clear if I need to completely change all the logic and dofig features, then it is easier to write a new one, but if it is a matter of one filter, then it still seems to me possible to get rid of the standard condition. I can be wrong, the opinion is subjective. - trec
      • There are groups and rights, but they are for use in the site, including in writing written interfaces for moderators (for example, I don’t believe in the competence of non-programmers to understand Django’s bare admin panel and do not bother with anything). Those. admin - such a thing where at a low level you can add / remove / fix something. For example, laziness to make an interface for an action that takes place every 2 years (say, to set the same rights) - went into the admin area and did it there, but letting everyone in there ... It is not advisable and dangerous. - qnub
      • Do not quite agree. Django admin panel is so simple that there the child will understand. What is not to be broken, Duc is needed for this, if I authorize adding materials, then apart from adding a new one (filling out 4 lines and selecting one photo), they don’t know anything else, and they don’t see anything else. Although for such actions to write your admin area is certainly cool, while making it unique and usable. By this I think that it depends on the desire of the implementer. And you can do so and so. IMHO creators would not mind 2 ways. - trec
      • In general, django is such a thing, like a python, anything can be ... I just don’t think that admin panel tweaking (including design) is simpler than creating several pages with forms and output limited in advance by necessary requirements and carrying out all the necessary checks and additional manipulations. But, of course, in each case there are more optimal options. - qnub