[Django]-Validate object attribute in manager in Django

5👍

I think it would be more appropriate to define TYPE_PENDING in the model itself:

class MyModel(models.Model):
    TYPE_PENDING = 1
    ...

    @property
    def is_pending(self):
        return self.type == self.TYPE_PENDING

    objects = MyManager()

...

class MyManager(models.Manager):
    def pending():
        return self.filter(type=self.model.TYPE_PENDING)
👤dgel

Leave a comment