2010-10-11 12:55:17 +00:00
|
|
|
from django.db import models, DEFAULT_DB_ALIAS, connection
|
2007-07-20 12:07:58 +00:00
|
|
|
from django.contrib.auth.models import User
|
2007-09-15 00:08:08 +00:00
|
|
|
from django.conf import settings
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2007-04-06 02:25:58 +00:00
|
|
|
|
|
|
|
class Animal(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
name = models.CharField(max_length=150)
|
|
|
|
latin_name = models.CharField(max_length=150)
|
2008-08-24 08:12:13 +00:00
|
|
|
count = models.IntegerField()
|
2009-01-03 04:43:58 +00:00
|
|
|
weight = models.FloatField()
|
2008-11-06 11:19:13 +00:00
|
|
|
|
2009-06-09 13:14:40 +00:00
|
|
|
# use a non-default name for the default manager
|
|
|
|
specimens = models.Manager()
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 12:11:04 +00:00
|
|
|
def __unicode__(self):
|
2009-12-14 12:39:20 +00:00
|
|
|
return self.name
|
2007-04-06 02:25:58 +00:00
|
|
|
|
2008-08-24 08:12:13 +00:00
|
|
|
|
2007-04-17 11:11:26 +00:00
|
|
|
class Plant(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
name = models.CharField(max_length=150)
|
2007-04-17 11:11:26 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
# For testing when upper case letter in app name; regression for #4057
|
|
|
|
db_table = "Fixtures_regress_plant"
|
|
|
|
|
2007-07-20 12:07:58 +00:00
|
|
|
class Stuff(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
name = models.CharField(max_length=20, null=True)
|
2007-07-20 12:07:58 +00:00
|
|
|
owner = models.ForeignKey(User, null=True)
|
2008-06-30 00:38:14 +00:00
|
|
|
|
2007-07-20 12:07:58 +00:00
|
|
|
def __unicode__(self):
|
2007-09-15 00:08:08 +00:00
|
|
|
# Oracle doesn't distinguish between None and the empty string.
|
|
|
|
# This hack makes the test case pass using Oracle.
|
|
|
|
name = self.name
|
2010-10-11 12:55:17 +00:00
|
|
|
if (connection.features.interprets_empty_strings_as_nulls
|
2009-12-22 15:18:51 +00:00
|
|
|
and name == u''):
|
2007-09-15 00:08:08 +00:00
|
|
|
name = None
|
|
|
|
return unicode(name) + u' is owned by ' + unicode(self.owner)
|
2007-07-20 12:07:58 +00:00
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2008-02-22 12:50:10 +00:00
|
|
|
class Absolute(models.Model):
|
|
|
|
name = models.CharField(max_length=40)
|
|
|
|
|
|
|
|
load_count = 0
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(Absolute, self).__init__(*args, **kwargs)
|
|
|
|
Absolute.load_count += 1
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2008-06-30 00:38:14 +00:00
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2010-03-18 15:22:15 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2008-06-30 00:38:14 +00:00
|
|
|
class Child(Parent):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-07-27 14:32:30 +00:00
|
|
|
# Models to regression test #7572
|
2008-06-30 12:18:29 +00:00
|
|
|
class Channel(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2008-06-30 12:18:29 +00:00
|
|
|
class Article(models.Model):
|
|
|
|
title = models.CharField(max_length=255)
|
|
|
|
channels = models.ManyToManyField(Channel)
|
2008-11-06 11:19:13 +00:00
|
|
|
|
2008-06-30 12:18:29 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
2008-02-22 12:50:10 +00:00
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-07-27 14:32:30 +00:00
|
|
|
# Models to regression test #11428
|
|
|
|
class Widget(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-07-27 14:32:30 +00:00
|
|
|
class WidgetProxy(Widget):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
# Check for forward references in FKs and M2Ms with natural keys
|
2009-12-14 12:39:20 +00:00
|
|
|
class TestManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, key):
|
|
|
|
return self.get(name=key)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Store(models.Model):
|
|
|
|
objects = TestManager()
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.name,)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Person(models.Model):
|
|
|
|
objects = TestManager()
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
# Person doesn't actually have a dependency on store, but we need to define
|
|
|
|
# one to test the behaviour of the dependency resolution algorithm.
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.name,)
|
|
|
|
natural_key.dependencies = ['fixtures_regress.store']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-14 12:39:20 +00:00
|
|
|
class Book(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
author = models.ForeignKey(Person)
|
|
|
|
stores = models.ManyToManyField(Store)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s by %s (available at %s)' % (
|
|
|
|
self.name,
|
|
|
|
self.author.name,
|
|
|
|
', '.join(s.name for s in self.stores.all())
|
|
|
|
)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2010-03-18 15:22:15 +00:00
|
|
|
class NKManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, data):
|
|
|
|
return self.get(data=data)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2010-03-18 15:22:15 +00:00
|
|
|
class NKChild(Parent):
|
|
|
|
data = models.CharField(max_length=10, unique=True)
|
|
|
|
objects = NKManager()
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return self.data
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'NKChild %s:%s' % (self.name, self.data)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2010-03-18 15:22:15 +00:00
|
|
|
class RefToNKChild(models.Model):
|
|
|
|
text = models.CharField(max_length=10)
|
|
|
|
nk_fk = models.ForeignKey(NKChild, related_name='ref_fks')
|
|
|
|
nk_m2m = models.ManyToManyField(NKChild, related_name='ref_m2ms')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u'%s: Reference to %s [%s]' % (
|
|
|
|
self.text,
|
|
|
|
self.nk_fk,
|
|
|
|
', '.join(str(o) for o in self.nk_m2m.all())
|
|
|
|
)
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
# ome models with pathological circular dependencies
|
|
|
|
class Circle1(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle2']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
class Circle2(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle1']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
class Circle3(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle3']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
class Circle4(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle5']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
class Circle5(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle6']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
class Circle6(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle4']
|
|
|
|
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
class ExternalDependency(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 14:52:20 +00:00
|
|
|
|
2009-12-17 21:54:37 +00:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.book']
|
|
|
|
|