App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / regressiontests / managers_regress / models.py
blobfb6c530722ec37a1e47719470fbcc8c1ee72df34
1 """
2 Various edge-cases for model managers.
3 """
5 from django.db import models
8 class OnlyFred(models.Manager):
9 def get_query_set(self):
10 return super(OnlyFred, self).get_query_set().filter(name='fred')
12 class OnlyBarney(models.Manager):
13 def get_query_set(self):
14 return super(OnlyBarney, self).get_query_set().filter(name='barney')
16 class Value42(models.Manager):
17 def get_query_set(self):
18 return super(Value42, self).get_query_set().filter(value=42)
20 class AbstractBase1(models.Model):
21 name = models.CharField(max_length=50)
23 class Meta:
24 abstract = True
26 # Custom managers
27 manager1 = OnlyFred()
28 manager2 = OnlyBarney()
29 objects = models.Manager()
31 class AbstractBase2(models.Model):
32 value = models.IntegerField()
34 class Meta:
35 abstract = True
37 # Custom manager
38 restricted = Value42()
40 # No custom manager on this class to make sure the default case doesn't break.
41 class AbstractBase3(models.Model):
42 comment = models.CharField(max_length=50)
44 class Meta:
45 abstract = True
47 class Parent(models.Model):
48 name = models.CharField(max_length=50)
50 manager = OnlyFred()
52 def __unicode__(self):
53 return self.name
55 # Managers from base classes are inherited and, if no manager is specified
56 # *and* the parent has a manager specified, the first one (in the MRO) will
57 # become the default.
58 class Child1(AbstractBase1):
59 data = models.CharField(max_length=25)
61 def __unicode__(self):
62 return self.data
64 class Child2(AbstractBase1, AbstractBase2):
65 data = models.CharField(max_length=25)
67 def __unicode__(self):
68 return self.data
70 class Child3(AbstractBase1, AbstractBase3):
71 data = models.CharField(max_length=25)
73 def __unicode__(self):
74 return self.data
76 class Child4(AbstractBase1):
77 data = models.CharField(max_length=25)
79 # Should be the default manager, although the parent managers are
80 # inherited.
81 default = models.Manager()
83 def __unicode__(self):
84 return self.data
86 class Child5(AbstractBase3):
87 name = models.CharField(max_length=25)
89 default = OnlyFred()
90 objects = models.Manager()
92 def __unicode__(self):
93 return self.name
95 # Will inherit managers from AbstractBase1, but not Child4.
96 class Child6(Child4):
97 value = models.IntegerField()
99 # Will not inherit default manager from parent.
100 class Child7(Parent):
101 pass