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):
for evidence in queryset:
evidence.profile.identity_verified = "approved"
evidence.profile.save()
make_approved.short_description = "Approve selected evidences"
def make_denied(modeladmin, request, queryset):
for evidence in queryset:
evidence.profile.identity_verified = "denied"
evidence.profile.save()
make_denied.short_description = "Deny selected evidences"
在 EvidenceAdmin ModelAdmin类的 get_actions 函数中,我将给出特殊条件,例如EvidenceFilter的所选值等于*pending*
。
if self.list_filter[0].value()=='pending':
但是我无法使用 self.list_filter [0] .value()来获取EvidenceFilter的选定值。 因为它我收到以下错误。
TypeError at /admin/securities/evidence/
value() missing 1 required positional argument: 'self'
任何建议或改进都是欢迎。需要一些指导...谢谢...