Opened 4 years ago

Closed 4 years ago

#32462 closed Uncategorized (invalid)

Django ORM get_readonly_fields, action on a ONE table row

Reported by: Naum Klaiderman Owned by: nobody
Component: contrib.admin Version: 3.1
Severity: Normal Keywords: get_readonly_fields
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello dear Django experts!
I ask for help in this matter:
There is a code:


def get_readonly_fields(self, request, obj=None):
 
        all_fields = list(self.get_fields(request, obj))
        user_blocked_fields = all_fields[:]
        iskom = 'SELFDISPOSAL'
        naxodim = Articles.objects.filter(delivery_type__title__icontains=iskom)
 
        if request.user.has_perm('excels.can_edit_manager_group'):
            user_blocked_fields = [f for f in user_blocked_fields if f not in self.manager_group_fields]
 
        if request.user.has_perm('excels.can_edit_upakovka_group'):
            user_blocked_fields = [f for f in user_blocked_fields if f not in self.upakovka_group_fields]
 
        if request.user.has_perm('excels.can_edit_transport_group'):
            user_blocked_fields = [f for f in user_blocked_fields if f not in self.transport_group_fields]
 
        # if request.user.has_perm('excels.can_edit_manager_group') and naxodim:
        #     user_blocked_fields = [f for f in user_blocked_fields if f not in self.manager_and_transport_group_fields]
        #
        # if request.user.has_perm('excels.can_edit_transport_group') and naxodim:
        #     user_blocked_fields = [f for f in user_blocked_fields if f not in self.transport_minus_all_group_fields]
 
        return user_blocked_fields"

It turns out that I have a change of permissions for editing fields depending on user rights.
further I want to make permission not for the whole table, but only for ONE ROW of the table.
That is, when you enter one record in the table and put the word "SELFDISPOSAL" in FK there, then you write down and then some readonlu_fields change fields to others.
This happens on my filter, but for the whole table (class), and I need ONLY ONE LINE WHERE I HAVE THE SPECIFIED WORD "SELFDISPOSAL" IN ONE OF THE FIELDS.!
How should I do it?
Thanks to everyone who responds!


Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

Please don't use Trac as a support channel. Closing per TicketClosingReasons/UseSupportChannels.

Note: See TracTickets for help on using tickets.
Back to Top