parts/django/tests/regressiontests/custom_managers_regress/models.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 """
       
     2 Regression tests for custom manager classes.
       
     3 """
       
     4 
       
     5 from django.db import models
       
     6 
       
     7 class RestrictedManager(models.Manager):
       
     8     """
       
     9     A manager that filters out non-public instances.
       
    10     """
       
    11     def get_query_set(self):
       
    12         return super(RestrictedManager, self).get_query_set().filter(is_public=True)
       
    13 
       
    14 class RelatedModel(models.Model):
       
    15     name = models.CharField(max_length=50)
       
    16 
       
    17     def __unicode__(self):
       
    18         return self.name
       
    19 
       
    20 class RestrictedModel(models.Model):
       
    21     name = models.CharField(max_length=50)
       
    22     is_public = models.BooleanField(default=False)
       
    23     related = models.ForeignKey(RelatedModel)
       
    24 
       
    25     objects = RestrictedManager()
       
    26     plain_manager = models.Manager()
       
    27 
       
    28     def __unicode__(self):
       
    29         return self.name
       
    30 
       
    31 class OneToOneRestrictedModel(models.Model):
       
    32     name = models.CharField(max_length=50)
       
    33     is_public = models.BooleanField(default=False)
       
    34     related = models.OneToOneField(RelatedModel)
       
    35 
       
    36     objects = RestrictedManager()
       
    37     plain_manager = models.Manager()
       
    38 
       
    39     def __unicode__(self):
       
    40         return self.name