mirror of
https://github.com/django/django.git
synced 2024-12-25 18:46:22 +00:00
e2ff11c6a3
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13866 bcc190cf-cafb-0310-a4f2-bffc1f526a37
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
"""
|
|
Regression tests for custom manager classes.
|
|
"""
|
|
|
|
from django.db import models
|
|
|
|
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)
|
|
|
|
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):
|
|
name = models.CharField(max_length=50)
|
|
is_public = models.BooleanField(default=False)
|
|
related = models.OneToOneField(RelatedModel)
|
|
|
|
objects = RestrictedManager()
|
|
plain_manager = models.Manager()
|
|
|
|
def __unicode__(self):
|
|
return self.name
|