B
B
Boldy2014-11-03 23:45:43
Django
Boldy, 2014-11-03 23:45:43

How to create custom filter in django?

There is the following model:

class Client(models.Model):
    @property
    def is_defaulter(self):
        if self.total_paid >= 72000:
            return False
        first_payment_date = self.contract_date
        first_payment_date.replace(day=10,
                                   month=first_payment_date.month + 1 if date.today().day <= 25
                                   else first_payment_date + 2)
        return ((date.today() - first_payment_date).month + 1) * 6000 > self.total_paid

It is necessary to create a boolean filter that will select clients according to the above algorithm. I tried to specify is_defaulter in list_filter, but the exception "there is no such field" took off.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-11-04
@Boldy

There is no such possibility. You can pervert like this
clients = [x for x in Client.objects.all() if x.is_defaulter]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question