I'm using a CustomQuerySet using Custom QuerySet and Manager without breaking DRY?. I can only access custom functions using objects
. Here's my Code:
class CustomQuerySetManager(models.Manager):
"""A re-usable Manager to access a custom QuerySet"""
def __getattr__(self, attr, *args):
print(attr)
try:
return getattr(self.__class__, attr, *args)
except AttributeError:
# don't delegate internal methods to the queryset
if attr.startswith('__') and attr.endswith('__'):
raise
return getattr(self.get_query_set(), attr, *args)
def get_query_set(self):
return self.model.QuerySet(self.model, using=self._db)
class SampleModel(models.Model):
objects = CustomQuerySetManager()
class QuerySet(models.QuerySet):
def test(self):
print("test function was callsed")
With this these happens:
SampleModel.objects.test() # This works
SampleModel.objects.all().test() # This doesnt works...
Why does this happen?