2009-03-15 04:41:33 +01:00
|
|
|
"""
|
|
|
|
Regression tests for custom manager classes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2009-03-15 04:41:33 +01:00
|
|
|
|
2011-10-13 20:51:33 +02:00
|
|
|
|
2009-03-15 04:41:33 +01:00
|
|
|
class RestrictedManager(models.Manager):
|
|
|
|
"""
|
|
|
|
A manager that filters out non-public instances.
|
|
|
|
"""
|
2013-03-08 15:15:23 +01:00
|
|
|
def get_queryset(self):
|
|
|
|
return super(RestrictedManager, self).get_queryset().filter(is_public=True)
|
2009-03-15 04:41:33 +01:00
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-03-20 04:57:12 +01:00
|
|
|
class RelatedModel(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-20 04:57:12 +01:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-03-20 04:57:12 +01: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 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-20 04:57:12 +01:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 05:36:09 +01:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2009-03-20 04:57:12 +01:00
|
|
|
class OneToOneRestrictedModel(models.Model):
|
2009-03-15 04:41:33 +01:00
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
is_public = models.BooleanField(default=False)
|
2009-03-20 04:57:12 +01:00
|
|
|
related = models.OneToOneField(RelatedModel)
|
2009-03-15 04:41:33 +01:00
|
|
|
|
|
|
|
objects = RestrictedManager()
|
|
|
|
plain_manager = models.Manager()
|
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2009-03-15 04:41:33 +01:00
|
|
|
return self.name
|