3 ms·
A few years ago I was experimenting with exactly this problem, and I came up with an API that worked using an inner class on the model. I can't find the code no
by simonw 15y ago
A few years ago I was experimenting with exactly this problem, and I came up with an API that worked using an inner class on the model. I can't find the code now, but from memory it looked something like this:
class BlogEntry(models.Model, MagicManagerMixin):
title = models.CharField(max_length = 128)
is_published = models.BooleanField(default = False)
class QuerySet(models.QuerySet):
def published(self):
return self.filter(is_published = True)
entries = BlogEntry.objects.published()
Where MagicManagerMixin was some scary code that made sure the objects Manager would use the queryset subclass.