2009-03-15 03:41:33 +00:00
|
|
|
"""
|
|
|
|
Regression tests for custom manager classes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
2012-08-12 10:32:08 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2009-03-15 03:41:33 +00:00
|
|
|
|
2011-10-13 18:51:33 +00:00
|
|
|
|
2009-03-15 03:41:33 +00:00
|
|
|
class RestrictedManager(models.Manager):
|
|
|
|
"""
|
|
|
|
A manager that filters out non-public instances.
|
|
|
|
"""
|
|
|
|
def get_query_set(self):
|
|
|
|
return super(RestrictedManager, self).get_query_set().filter(is_public=True)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-03-20 03:57:12 +00:00
|
|
|
class RelatedModel(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-20 03:57:12 +00:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-03-20 03:57:12 +00:00
|
|
|
class RestrictedModel(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
is_public = models.BooleanField(default=False)
|
|
|
|
related = models.ForeignKey(RelatedModel)
|
|
|
|
|
|
|
|
objects = RestrictedManager()
|
|
|
|
plain_manager = models.Manager()
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-20 03:57:12 +00:00
|
|
|
return self.name
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
@python_2_unicode_compatible
|
2009-03-20 03:57:12 +00:00
|
|
|
class OneToOneRestrictedModel(models.Model):
|
2009-03-15 03:41:33 +00:00
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
is_public = models.BooleanField(default=False)
|
2009-03-20 03:57:12 +00:00
|
|
|
related = models.OneToOneField(RelatedModel)
|
2009-03-15 03:41:33 +00:00
|
|
|
|
|
|
|
objects = RestrictedManager()
|
|
|
|
plain_manager = models.Manager()
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2009-03-15 03:41:33 +00:00
|
|
|
return self.name
|