Hi
Here i want to exclude some model filed depending upon type of User.
Example if username is "dgp", i want to exclude
in admin.py
if username == "dgp":
self.exclude = ("UserNext","UserNextDate","UserNextDepartment","CaseStatus")
self.exclude = ("UserNext","UserNextDate","UserNextDepartment","CaseStatus")
in
def 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.
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 error
KeyError 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.py
class 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'
)
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):
'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 form
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 form
Can 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 working
FieldError at /admin/newapp/profile/
Related Field got invalid lookup: icontains
Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,
Asst. Professor
Department of Information Technology,
SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India
Official: bsshetty@sggs.ac.in
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/CAECSbOvnO8bkkwAqhOJThtnCRRsRJVVzvT68vYkaxTEvpyM0tA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment