PageRenderTime 119ms CodeModel.GetById 66ms app.highlight 17ms RepoModel.GetById 33ms app.codeStats 0ms

/tests/regressiontests/fixtures_regress/models.py

https://code.google.com/p/mango-py/
Python | 225 lines | 139 code | 77 blank | 9 comment | 4 complexity | 3ba8b59e473469eb9976b32c040400ad MD5 | raw file
  1from django.db import models, DEFAULT_DB_ALIAS, connection
  2from django.contrib.auth.models import User
  3from django.conf import settings
  4
  5
  6class Animal(models.Model):
  7    name = models.CharField(max_length=150)
  8    latin_name = models.CharField(max_length=150)
  9    count = models.IntegerField()
 10    weight = models.FloatField()
 11
 12    # use a non-default name for the default manager
 13    specimens = models.Manager()
 14
 15    def __unicode__(self):
 16        return self.name
 17
 18
 19class Plant(models.Model):
 20    name = models.CharField(max_length=150)
 21
 22    class Meta:
 23        # For testing when upper case letter in app name; regression for #4057
 24        db_table = "Fixtures_regress_plant"
 25
 26class Stuff(models.Model):
 27    name = models.CharField(max_length=20, null=True)
 28    owner = models.ForeignKey(User, null=True)
 29
 30    def __unicode__(self):
 31        return unicode(self.name) + u' is owned by ' + unicode(self.owner)
 32
 33
 34class Absolute(models.Model):
 35    name = models.CharField(max_length=40)
 36
 37    load_count = 0
 38
 39    def __init__(self, *args, **kwargs):
 40        super(Absolute, self).__init__(*args, **kwargs)
 41        Absolute.load_count += 1
 42
 43
 44class Parent(models.Model):
 45    name = models.CharField(max_length=10)
 46
 47    class Meta:
 48        ordering = ('id',)
 49
 50
 51class Child(Parent):
 52    data = models.CharField(max_length=10)
 53
 54
 55# Models to regression test #7572
 56class Channel(models.Model):
 57    name = models.CharField(max_length=255)
 58
 59
 60class Article(models.Model):
 61    title = models.CharField(max_length=255)
 62    channels = models.ManyToManyField(Channel)
 63
 64    class Meta:
 65        ordering = ('id',)
 66
 67
 68# Models to regression test #11428
 69class Widget(models.Model):
 70    name = models.CharField(max_length=255)
 71
 72    class Meta:
 73        ordering = ('name',)
 74
 75    def __unicode__(self):
 76        return self.name
 77
 78
 79class WidgetProxy(Widget):
 80    class Meta:
 81        proxy = True
 82
 83
 84# Check for forward references in FKs and M2Ms with natural keys
 85class TestManager(models.Manager):
 86    def get_by_natural_key(self, key):
 87        return self.get(name=key)
 88
 89
 90class Store(models.Model):
 91    objects = TestManager()
 92    name = models.CharField(max_length=255)
 93
 94    class Meta:
 95        ordering = ('name',)
 96
 97    def __unicode__(self):
 98        return self.name
 99
100    def natural_key(self):
101        return (self.name,)
102
103
104class Person(models.Model):
105    objects = TestManager()
106    name = models.CharField(max_length=255)
107
108    class Meta:
109        ordering = ('name',)
110
111    def __unicode__(self):
112        return self.name
113
114    # Person doesn't actually have a dependency on store, but we need to define
115    # one to test the behaviour of the dependency resolution algorithm.
116    def natural_key(self):
117        return (self.name,)
118    natural_key.dependencies = ['fixtures_regress.store']
119
120
121class Book(models.Model):
122    name = models.CharField(max_length=255)
123    author = models.ForeignKey(Person)
124    stores = models.ManyToManyField(Store)
125
126    class Meta:
127        ordering = ('name',)
128
129    def __unicode__(self):
130        return u'%s by %s (available at %s)' % (
131            self.name,
132            self.author.name,
133            ', '.join(s.name for s in self.stores.all())
134        )
135
136
137class NKManager(models.Manager):
138    def get_by_natural_key(self, data):
139        return self.get(data=data)
140
141
142class NKChild(Parent):
143    data = models.CharField(max_length=10, unique=True)
144    objects = NKManager()
145
146    def natural_key(self):
147        return self.data
148
149    def __unicode__(self):
150        return u'NKChild %s:%s' % (self.name, self.data)
151
152
153class RefToNKChild(models.Model):
154    text = models.CharField(max_length=10)
155    nk_fk = models.ForeignKey(NKChild, related_name='ref_fks')
156    nk_m2m = models.ManyToManyField(NKChild, related_name='ref_m2ms')
157
158    def __unicode__(self):
159        return u'%s: Reference to %s [%s]' % (
160            self.text,
161            self.nk_fk,
162            ', '.join(str(o) for o in self.nk_m2m.all())
163        )
164
165
166# ome models with pathological circular dependencies
167class Circle1(models.Model):
168    name = models.CharField(max_length=255)
169
170    def natural_key(self):
171        return self.name
172    natural_key.dependencies = ['fixtures_regress.circle2']
173
174
175class Circle2(models.Model):
176    name = models.CharField(max_length=255)
177
178    def natural_key(self):
179        return self.name
180    natural_key.dependencies = ['fixtures_regress.circle1']
181
182
183class Circle3(models.Model):
184    name = models.CharField(max_length=255)
185
186    def natural_key(self):
187        return self.name
188    natural_key.dependencies = ['fixtures_regress.circle3']
189
190
191class Circle4(models.Model):
192    name = models.CharField(max_length=255)
193
194    def natural_key(self):
195        return self.name
196    natural_key.dependencies = ['fixtures_regress.circle5']
197
198
199class Circle5(models.Model):
200    name = models.CharField(max_length=255)
201
202    def natural_key(self):
203        return self.name
204    natural_key.dependencies = ['fixtures_regress.circle6']
205
206
207class Circle6(models.Model):
208    name = models.CharField(max_length=255)
209
210    def natural_key(self):
211        return self.name
212    natural_key.dependencies = ['fixtures_regress.circle4']
213
214
215class ExternalDependency(models.Model):
216    name = models.CharField(max_length=255)
217
218    def natural_key(self):
219        return self.name
220    natural_key.dependencies = ['fixtures_regress.book']
221
222
223# Model for regression test of #11101
224class Thingy(models.Model):
225    name = models.CharField(max_length=255)