PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/regressiontests/custom_managers_regress/models.py

https://code.google.com/p/mango-py/
Python | 40 lines | 24 code | 10 blank | 6 comment | 0 complexity | c9c3784a0d7c346d9cf9eb47510834e5 MD5 | raw file
 1"""
 2Regression tests for custom manager classes.
 3"""
 4
 5from django.db import models
 6
 7class 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
14class RelatedModel(models.Model):
15    name = models.CharField(max_length=50)
16
17    def __unicode__(self):
18        return self.name
19
20class 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
31class 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