Your first error refers to a ProfileForm; you need to post the form definition code here as well.
On Sunday, 26 May 2019 20:48:09 UTC+2, Balaji wrote:
-- On Sunday, 26 May 2019 20:48:09 UTC+2, Balaji wrote:
HiHere i want to exclude some model filed depending upon type of User.Example if username is "dgp", i want to excludein admin.pyif username == "dgp":
self.exclude = ("UserNext","UserNextDate","UserNextDepartment"," CaseStatus") indef get_form(self, request, obj=None, **kwargs):
I do not use fieldset and comment the code, i get field excluded in "dgp" Login. Code execute successfully and fields get excluded.But if i use filedset, I get the errorKeyError at /admin/newapp/profile/add/
"Key 'UserNext' not found in 'ProfileForm'. Choices are: CaseActionTaken,
CaseAdvocate, CaseInwardDate, CaseLastDate, CaseNoticeDate, CaseNoticeSubject,4
CaseNumber, CaseOppositePartyNames, CasePartyNames, CaseReceiverName,
CaseSubject, CaseSubmittedDate, CaseYear, CourtType, District,
InwardNumber, State, SuitType, user."------------------------------------------ here is admin.pyclass ProfileAdmin(admin.ModelAdmin):
save_on_top = True
save_as = True
list_display = ('user','CaseNumber','CaseYear','InwardNumber',' CaseNoticeDate',' CaseNoticeSubject',
'CaseReceiverName','CaseInwardDate',' CaseActionTaken',' CaseAdvocate','CasePartyNames' ,
'CaseOppositePartyNames','CaseLastDate','user',' UserNext','UserNextDate',' UserNextDepartment',' CaseStatus'
)search_fields = ['user','CaseNumber','CaseYear','InwardNumber',' CaseNoticeDate',' CaseNoticeSubject',
'CaseReceiverName','CaseInwardDate',' CaseActionTaken',' CaseAdvocate','CasePartyNames' ,
'CaseOppositePartyNames','CaseLastDate','user',' UserNext','UserNextDate',' UserNextDepartment',' CaseStatus'
]
fieldsets = [
('Location information',
{'fields': ['State','District','user'] } ),
('Department Internal information', {'classes':['collapse'],'fields': [ ('InwardNumber',' CaseInwardDate'),
('CaseNoticeSubject','CaseNoticeDate',),(' CaseReceiverName',' CaseActionTaken') ] } ),
('Court Case Information', {'classes':['collapse'],
'fields': [ ('CourtType','SuitType'),
('CaseYear','CaseNumber'),('CaseSubject',' CaseSubmittedDate') ] } ),
('Party Information', {'classes':['collapse'],
'fields': [ ('CaseAdvocate'),
('CasePartyNames','CaseOppositePartyNames'),' CaseLastDate' ] } ),
('Incharge Officer Information', {'classes':['collapse'],
'fields': [ ('UserNext','UserNextDate'),
('UserNextDepartment','CaseStatus') ] } )
]
list_per_page = 5
def get_form(self, request, obj=None, **kwargs):username = request.user.username
print (username)
if username == "dgp":
self.exclude = ("UserNext","UserNextDate","UserNextDepartment"," CaseStatus")
# self.exclude = ("location","birth_date","bio", )
form = super(ProfileAdmin, self).get_form(request, obj, **kwargs)
return form
else:
form = super(ProfileAdmin, self).get_form(request, obj, **kwargs)
return formCan anybody help me in this regards.If i comment Fieldset, than code works in "dgp" login with hiding necessary fields.Also my search is not workingFieldError at /admin/newapp/profile/
Related Field got invalid lookup: icontains--Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.IndiaOfficial: bssh...@sggs.ac.inMobile: +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/555a679b-3b7f-4275-823e-383b380865f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment