Using Django model manager to return a queryset based on a complex class method

I have a model called Stockentry:

class Stockentry(models.Model):
    id = models.AutoField(primary_key=True, unique=True)
    distributor = models.ForeignKey(
        Distributor, blank=True, null=True, on_delete=models.SET_NULL)
    ...
    
    def is_payment_overdue(self):
        days = self.daysdue()
        if self.paid == True:
            # Already paid
            return False
        # Not already paid
        try:
            if days >= self.distributor.credit_days:
                # Is overdue if has already exceeded the credit period extended by distributor to dealer
                return True
            else:
                # Is not overdue
                return False
        except:
            # TODO. Currently a temporary catchall
            return False
    

I am using DRF. I wish to have a query like this to return a queryset where is_payment_overdue is True

stockentries = Stockentry.objects.filter(store=store).is_overdue()

I started like this:

class StockentryManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset()
    
    def is_overdue(self):
        myset = super().get_queryset()
        

And went through the docs, but couldnt understand how to utilize this to my specific scenario. I also came across a SO post, which wasnt a minimal complete example, and lacked specifics of implementation. Kindly explain how to go about implementing this for my code.

Back to Top