0
を支払っただけで候補者を返すようにフィルタリングしないことジャンゴ:どのように私はここ> = 10000
class Candidate(models.Model):
person = models.OneToOneField(
Person, related_name='person_candidate', on_delete=models.PROTECT)
def __str__(self):
return str(self.person)
@property
def total_candidate_votes(self):
return self.candidate_votes.filter(candidate=self).count()
@property
def amount_paid(self):
return self.candidate_payments.aggregate(models.Sum('fees'))['fees__sum'] or 0
@property
def is_qualified_to_vie(self):
return self.amount_paid >= 10000
は私だけ> = 10000 を支払った候補が表示されますフィルタを作成するのに役立ち、私のmodel.pyですFilter.py
class CandidateFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='iexact', name='person__first_name')
is_qualified_to_vie = django_filters.BooleanFilter(method='filter_by_qualified_candidates')
def filter_by_qualified_candidates(self, queryset, field, value):
return queryset.filter