python - How to show dynamic custom actions by selected custom filter in Django -
class evidencefilter(simplelistfilter): title = _('evidence') parameter_name = 'evidence' def lookups(self, request, model_admin): return evidence_status_choices def queryset(self, request, queryset): if self.value(): if self.value() == 'pending': return queryset.filter(q(profile__identity_verified='pending') & (q(person_id_status='pending') | q(person_selfie_status='pending') | q(org_certificate_status='pending') | q(org_taxid_status='pending'))) elif self.value() == 'accepted': return queryset.filter(q(profile__identity_verified='pending') & ((q(person_id_status='accepted') & q(person_selfie_status='accepted')) | (q(org_certificate_status='accepted') & q(org_taxid_status='accepted')))) elif self.value() == 'rejected': return queryset.filter(q(profile__identity_verified='pending') & ((q(person_id_status='rejected') | q(person_selfie_status='rejected')) | (q(org_certificate_status='rejected') | q(org_taxid_status='rejected')))) else: return queryset class evidenceadmin(admin.modeladmin): list_display = ('id', 'profile', 'person_id_status', 'person_selfie_status', 'org_certificate_status', 'org_taxid_status') list_filter = (evidencefilter,) actions = ['make_approved', 'make_denied'] class meta: exclude = [] def get_actions(self, request): actions = super(evidenceadmin, self).get_actions(request) if self.list_filter[0].value()=='pending': if 'make_approved' in actions: del actions['make_approved'] if 'make_denied' in actions: del actions['make_denied'] return actions def make_approved(modeladmin, request, queryset): evidence in queryset: evidence.profile.identity_verified = "approved" evidence.profile.save() make_approved.short_description = "approve selected evidences" def make_denied(modeladmin, request, queryset): evidence in queryset: evidence.profile.identity_verified = "denied" evidence.profile.save() make_denied.short_description = "deny selected evidences"
in get_actions function of evidenceadmin modeladmin class going give special condition evidencefilter's selected value equal *pending*
.
if self.list_filter[0].value()=='pending':
but can't use self.list_filter[0].value() selected value of evidencefilter. following error because of it.
typeerror @ /admin/securities/evidence/ value() missing 1 required positional argument: 'self'
any suggestions or improvements welcome. need guidance on this... thanks...
Comments
Post a Comment