def extendManager(mixinClass):
class MixinManager(models.Manager, mixinClass):<EOL><INDENT>class MixinQuerySet(models.query.QuerySet, mixinClass):<EOL><INDENT>pass<EOL><DEDENT>def get_queryset(self):<EOL><INDENT>return self.MixinQuerySet(self.model, using = self._db)<EOL><DEDENT><DEDENT>return MixinManager()<EOL>
Use as a class decorator to add extra methods to your model manager.
Example usage:

        class Article(django.db.models.Model):
                published = models.DateTimeField()
                ...

                @extendManager
                class objects(object):
                        def getPublished(self):
                                return self.filter(published__lte = django.utils.timezone.now()).order_by('-published')

        ...

        publishedArticles = Article.objects.getPublished()