Ticket #15062: models.py

File models.py, 682 bytes (added by clelland, 5 years ago)

test_app/models.py for test project which reproduces error

Line 
1from django.db import models
2from django.contrib.auth.models import User
3
4
5class QuerySetManager(models.Manager):
6    """
7    Simon Willison's QuerySetManager
8    http://djangosnippets.org/snippets/734/
9
10    Enables adding new QuerySet methods using a Model inner class.
11    """
12
13    def get_query_set(self):
14        return self.model.QuerySet(self.model)
15
16    def __getattr__(self, attr, *args):
17        return getattr(self.get_query_set(), attr, *args)
18
19
20class TestModel(models.Model):
21
22    user = models.ForeignKey(User)
23    string = models.CharField(max_length=64, null=True, blank=True)
24
25    objects = QuerySetManager()
26
27    class QuerySet(models.query.QuerySet):
28        pass
Back to Top