2009-03-15 11:41:33 +08:00
|
|
|
"""
|
|
|
|
Regression tests for custom manager classes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
2011-10-14 02:51:33 +08:00
|
|
|
|
2009-03-15 11:41:33 +08: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)
|
|
|
|
|
2009-03-20 11:57:12 +08:00
|
|
|
class RelatedModel(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class OneToOneRestrictedModel(models.Model):
|
2009-03-15 11:41:33 +08:00
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
is_public = models.BooleanField(default=False)
|
2009-03-20 11:57:12 +08:00
|
|
|
related = models.OneToOneField(RelatedModel)
|
2009-03-15 11:41:33 +08:00
|
|
|
|
|
|
|
objects = RestrictedManager()
|
|
|
|
plain_manager = models.Manager()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|