Tuesday, May 28, 2019

SOLUTION FounD : How to restore Models original Properties - Problem in Models column Exclude

This is the proper code to customize models column userwise.
Here we are sharing model among multiple user and depending upon right access, it is visible

in admin.py

  normaluser_fields = ['user','CourtType','SuitType','CaseNumber','CaseYear','CaseAdvocate','CasePartyNames',
                    'CaseOppositePartyNames','CaseLastDate']
  superuser_fields = ['UserNext','UserNextDate','UserNextDepartment','CaseStatus']
  inward_fields = ['InwardNumber','CaseNoticeDate','CaseNoticeSubject','CaseReceiverName','CaseInwardDate','CaseActionTaken']


  def get_form(self, request, obj=None, **kwargs):

        username = request.user.username
   
        print("----- Inside get_exclude Method--------")
        print (username)

        if username == 'dgp': # if user is not a superuser
       
        # if request.user.is_superuser:
            # print("-----  ***********  Inside ROOT LOGIN ***-------")

            self.fields = self.normaluser_fields
        elif username == 'inumber':
            print("-----  ***********  Inside DGP LOGIN ***-------")
            self.fields = self.inward_fields
        else:
            self.fields = self.normaluser_fields + self.superuser_fields + self.inward_fields
                 

        return super(ProfileAdmin, self).get_form(request, obj, **kwargs)



On Tue, May 28, 2019 at 1:02 PM Balaji Shetty <balajishetty@gmail.com> wrote:
Dear  Alexis Roda Sir

Thank You very much for your nice reply. I check it.

On Tue, May 28, 2019 at 1:55 AM Alexis Roda <alexis.roda.villalonga@gmail.com> wrote:
Not an admin expert here.

You are modifying the modeladmin instance and, by the behavior you're describing, it looks like it is a global (shared) object. I'm guessing, you can confirm this by printing id(self) in add_view(). I'll bet you get the same value in each request, so the instance is shared, so the change is visible (persisted) across request boundaries.

You may think about adding self.exclude = () in the else branch in order to not exclude anything. Don't do that, you may end up leaking private information to dgp if both root and dgp are logged in at the same time.

Instead override the get_exclude method.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMDYoXbb42hpu3jAATXTwxPw9kO8XeZpLOczbNa-Bzw5QAdGuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,
SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India
  Mobile: +91-9270696267



--
Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,
SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India
  Mobile: +91-9270696267

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAECSbOsDv%2Byx-D382S45y2%3DqfYo3FHxyUytqYDm%2B62DYkZopig%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment