2 Regression tests for custom manager classes.
5 from django
.db
import models
8 class RestrictedManager(models
.Manager
):
10 A manager that filters out non-public instances.
12 def get_query_set(self
):
13 return super(RestrictedManager
, self
).get_query_set().filter(is_public
=True)
15 class RelatedModel(models
.Model
):
16 name
= models
.CharField(max_length
=50)
18 def __unicode__(self
):
21 class RestrictedModel(models
.Model
):
22 name
= models
.CharField(max_length
=50)
23 is_public
= models
.BooleanField(default
=False)
24 related
= models
.ForeignKey(RelatedModel
)
26 objects
= RestrictedManager()
27 plain_manager
= models
.Manager()
29 def __unicode__(self
):
32 class OneToOneRestrictedModel(models
.Model
):
33 name
= models
.CharField(max_length
=50)
34 is_public
= models
.BooleanField(default
=False)
35 related
= models
.OneToOneField(RelatedModel
)
37 objects
= RestrictedManager()
38 plain_manager
= models
.Manager()
40 def __unicode__(self
):