Z
Z
zkweb2015-12-17 11:11:47
Django
zkweb, 2015-12-17 11:11:47

How to fix bug in Django - add_view?

There are 2 groups of users: sellers, store director
Well, and superadmin, who sees everything and can edit everything.
For the seller , when adding a record, certain fields are hidden, the same for the director .
Here is the code:

def add_view(self, request, form_url='', extra_context=None):
        if not request.user.is_superuser:
            if request.user.groups.all()[0].id == 2:
                self.exclude=('date_job', 'text_job', 'vendors_response', 'solution', 'response_buyer', 'status', 'user', 'shop')
            elif request.user.groups.all()[0].id == 4:
                self.exclude=('date_job', 'text_job', 'vendors_response', 'solution', 'response_buyer', 'status', 'user') 
            else:    
                self.exclude=('date_job')             
        return super(ClaimAdmin, self).add_view(request, form_url='', extra_context=None)

Problem: Two browsers are open. In one under the superadmin, in the other under the seller.
I add a record under the seller, everything is in order, the required fields are hidden.
I add under the superadmin, ALSO all the fields are hidden, I refresh the page (5 times) all the other fields are suddenly available, I update it again hidden (
How can this be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2015-12-17
@zkweb

exclude is a class field, not an object. In __init__ of the view write self.exclude = None

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question