Z
Z
zkweb2016-04-28 09:27:11
Django
zkweb, 2016-04-28 09:27:11

How to give access to your objects?

I'm new to Django, don't scold me!
There is such an action

review_template = 'admin/netsch/item_view.html'
    def item_view(self, request, id): 
        item = Netsch.objects.filter(pk=id)      
        works = Netschlistwork.objects.filter(netsch_id=id, type = 1).order_by("id")        
        works_admin = Netschlistwork.objects.filter(netsch_id=id, type = 2).order_by("id")       
        return render_to_response(self.review_template, {
            'item':item,
            'works':works,
            'works_admin':works_admin,
            'opts': self.model._meta,
        }, context_instance=RequestContext(request))

There are two groups of users: moderators , editors
Tell me how can I do the following:
1) moderators can have full access to item_view and view all posts there
2) editors can have access to item_view , but should not see posts of other editors there
def item_view(self , request, id):
* how can I set access levels here * ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2016-04-28
@zkweb

Check if moderator or not and filter queryset if not:

qs = Item.objects.all()
if not user.is_moderator:
    qs = qs.filter(user=user)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question