*Hi*

*i have encountered very strange problem.  have two user . One is superuser
of name "root" and another is general user of name "dgp". I have model of
Name Profile with 21 fields around.*

*I want to show all field of Model Profile in "root" login.*
*I want to exclude 4 field of Model Profile in "dgp" login.*

* I get correct output If i do login in this sequence root - dgp*
* I get wrong output If i do login in this sequence  dgp - root*
*( Means I get 4 field excluded in root Login also. )*
*Means once i do login using "dgp" user , i always get all 4 fields
excluded in subsequent login for any user unless and until i restart the
server.*

*I have a model of name Profile and I want to exclude four fields for user
of name  "dgp" .*


* Fields are *


* username = request.user.username    if username == "dgp":
 self.exclude =
('UserNext','UserNextDate','UserNextDepartment','CaseStatus', )*

*I have superuser as root.*
*1.  When I run the code and do the login using root user login*

*I get all Fields of Profile Model. *

*2 I do logout and Login Using "dgp" user. I get all Fields of Profile
Model except *
*the four fields.
'UserNext','UserNextDate','UserNextDepartment','CaseStatus', )*

*Here My code Execute successfully.*

*But when I change the sequence of Login, Code shows the *

* all Fields of Profile Model except *
*the four fields in both login "dgp" as well as "root".*

*I have overridden Models Two methods. Necessary Model and admin code is
shown below.*


*Please help n this regards.*



*models.py*

*-------------------------------*






































































*class Profile(models.Model):    RCS1 = "Regular_Civil_Suit"    SCS1 =
"Special_Civil_Suit"    RCA1 = "Regular Civil Appeal"    MCA1 =
"Miscellaneous Civil Appeal"    CMA1 = "Civil Miscellaneous Application"
LAR1 = "Land Acquisation Reference"    SED1 = "Special Execution Darkhast"
  # AC1 = "Arbitration Case"    SuitType_Choice = [           (RCS1,
'Regular Civil Suit'),           (SCS1, 'Special Civil Suit'),
 (RCA1, 'Regular Civil Appeal'),           (MCA1,'Miscellaneous Civil
Appeal'),           (CMA1,'Civil Miscellaneous Application'),
 (LAR1,'Land Acquisation Reference'),           (SED1,'Special Execution
Darkhast'),           # (AC1,’Arbitration Case’),      ]    State =
models.CharField(max_length=100,default="MH")    District =
models.CharField(max_length=100,default="Parbhani")       user =
models.ForeignKey(User, on_delete=models.CASCADE,default="--")
InwardNumber = models.CharField(max_length=100,default="2019/3")
CaseNoticeDate = models.DateField(default="2019-01-24")
CaseNoticeSubject = models.CharField(max_length=100,default="Inquiry in
Department")    CaseReceiverName =
models.CharField(max_length=100,default="Ramakant Lal")    CaseInwardDate =
models.DateField(default="2019-02-24")
CaseActionTaken=models.CharField(max_length=200,default="Verification is
going on")      CourtType
=models.CharField(max_length=200,default="District Court Parbhani")
SuitType= models.CharField(max_length=200,choices=SuitType_Choice,
default="Regular Civil Suit",verbose_name='--Suit Type-')     #
decision_taken = models.CharField(max_length=50, choices=court_action,
 #   default="Appeared",verbose_name='Court Decision-')      CaseYear =
models.PositiveIntegerField(default=2019)    CaseNumber =
models.PositiveIntegerField(default=1)    CaseSubmittedDate =
models.DateField(default="2019-01-14")    # Current_Date=
models.DateField(default=timezone.now)
CaseSubject=models.CharField(max_length=200,default="Corruption and
Dowry")      CaseAdvocate=models.CharField(max_length=200,default="Reguar
Civil Suit")
CasePartyNames=models.CharField(max_length=200,default="Manish Singh")
CaseOppositePartyNames=models.CharField(max_length=200,default="Raj Kumar
")    CaseLastDate = models.DateField(default="2019-05-24")     UserCurrent
=  models.CharField(max_length=200,default="user1")    UserCurrentDate =
models.DateField(default="2019-03-24")    UserCurrentDepartment =
 models.CharField(max_length=200,default="IT")       UserNext =
 models.CharField(max_length=200,default="user2")    UserNextDate =
models.DateField(default="2019-06-24")    UserNextDepartment =
 models.CharField(max_length=200,default="CS")        CaseStatus=
models.CharField(max_length=100,default="Pending")    # CaseNumber =
models.PositiveIntegerField(default=1)    # CaseYear =
models.PositiveIntegerField(default=2019)        class Meta:
unique_together = (('CaseNumber', 'CaseYear'),)         def __str__(self):
      return '%s/%s' % (self.CaseNumber, self.CaseYear)*
*-----------------------------------------------------------------------*




admin.py
+++++++++++++++++++++++++++++++++++++++++++






































*def add_view(self, request, extra_context=None):    username =
request.user.username        print("----- Inside ADD VIEW Method--------")
  print (username)    self._request = request            if username ==
"dgp":      print("----- Inside ADD VIEW DGP Condition--------")
self.exclude =
('UserNext','UserNextDate','UserNextDepartment','CaseStatus', )
else:         print("----- Inside ADD VIEW  ***NON DGP***
Condition--------")      # return super().add_view(request, extra_context)
  return super().changeform_view(request, extra_context)     def
change_view(self, request, object_id,  extra_context=None):        #
extra_context = extra_context or {}        # extra_context['osm_data'] =
self.get_osm_info()    username = request.user.username
print("Inside CHANGE VIEW Method--------")    print (username)    if
username == "dgp":       self.exclude =
('UserNext','UserNextDate','UserNextDepartment','CaseStatus', )
 print("----- Inside CHANGE VIEW  IN  DGP User Condition--------")
else:       print("----- Inside CHANGE VIEW **** other THAN DG**P User
Condition--------")            # self.include =
('UserNext','UserNextDate','UserNextDepartment','CaseStatus', )
return super().change_view(            request, object_id,
extra_context=extra_context,    )*


*+++++++++++++++++++++++++++++++++++++++++++++++*


-- 


*Mr. Shetty Balaji S.Asst. ProfessorDepartment of Information Technology,*
*SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India*
*Official: [email protected] <[email protected]> *
*  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 [email protected].
To post to this group, send email to [email protected].
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/CAECSbOugq%3DJifFO0CkFW9_Ra2A9T_CdxbvL42EwU%2B%2BX6u_b50Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to