2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2011-10-14 02:51:33 +08:00
|
|
|
|
2007-07-20 20:07:58 +08:00
|
|
|
from django.contrib.auth.models import User
|
2011-10-14 02:51:33 +08:00
|
|
|
from django.db import models
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2007-04-06 10:25:58 +08:00
|
|
|
|
|
|
|
class Animal(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=150)
|
|
|
|
latin_name = models.CharField(max_length=150)
|
2008-08-24 16:12:13 +08:00
|
|
|
count = models.IntegerField()
|
2009-01-03 12:43:58 +08:00
|
|
|
weight = models.FloatField()
|
2008-11-06 19:19:13 +08:00
|
|
|
|
2009-06-09 21:14:40 +08: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 20:11:04 +08:00
|
|
|
def __unicode__(self):
|
2009-12-14 20:39:20 +08:00
|
|
|
return self.name
|
2007-04-06 10:25:58 +08:00
|
|
|
|
2008-08-24 16:12:13 +08:00
|
|
|
|
2007-04-17 19:11:26 +08:00
|
|
|
class Plant(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=150)
|
2007-04-17 19:11:26 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
# For testing when upper case letter in app name; regression for #4057
|
|
|
|
db_table = "Fixtures_regress_plant"
|
|
|
|
|
2007-07-20 20:07:58 +08:00
|
|
|
class Stuff(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=20, null=True)
|
2007-07-20 20:07:58 +08:00
|
|
|
owner = models.ForeignKey(User, null=True)
|
2008-06-30 08:38:14 +08:00
|
|
|
|
2007-07-20 20:07:58 +08:00
|
|
|
def __unicode__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return unicode(self.name) + ' is owned by ' + unicode(self.owner)
|
2007-07-20 20:07:58 +08:00
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2008-02-22 20:50:10 +08: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 22:52:20 +08:00
|
|
|
|
2008-06-30 08:38:14 +08:00
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=10)
|
|
|
|
|
2010-03-18 23:22:15 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2008-06-30 08:38:14 +08:00
|
|
|
class Child(Parent):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-07-27 22:32:30 +08:00
|
|
|
# Models to regression test #7572
|
2008-06-30 20:18:29 +08:00
|
|
|
class Channel(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2008-06-30 20:18:29 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
title = models.CharField(max_length=255)
|
|
|
|
channels = models.ManyToManyField(Channel)
|
2008-11-06 19:19:13 +08:00
|
|
|
|
2008-06-30 20:18:29 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ('id',)
|
2008-02-22 20:50:10 +08:00
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-07-27 22:32:30 +08:00
|
|
|
# Models to regression test #11428
|
|
|
|
class Widget(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2009-12-14 20:39:20 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-07-27 22:32:30 +08:00
|
|
|
class WidgetProxy(Widget):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2009-12-14 20:39:20 +08:00
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
# Check for forward references in FKs and M2Ms with natural keys
|
2009-12-14 20:39:20 +08:00
|
|
|
class TestManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, key):
|
|
|
|
return self.get(name=key)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-14 20:39:20 +08: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 22:52:20 +08:00
|
|
|
|
2009-12-14 20:39:20 +08: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
|
2011-12-18 01:37:24 +08:00
|
|
|
# one to test the behavior of the dependency resolution algorithm.
|
2009-12-14 20:39:20 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return (self.name,)
|
|
|
|
natural_key.dependencies = ['fixtures_regress.store']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-14 20:39:20 +08: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):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '%s by %s (available at %s)' % (
|
2009-12-14 20:39:20 +08:00
|
|
|
self.name,
|
|
|
|
self.author.name,
|
|
|
|
', '.join(s.name for s in self.stores.all())
|
|
|
|
)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2010-03-18 23:22:15 +08:00
|
|
|
class NKManager(models.Manager):
|
|
|
|
def get_by_natural_key(self, data):
|
|
|
|
return self.get(data=data)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2010-03-18 23:22:15 +08:00
|
|
|
class NKChild(Parent):
|
|
|
|
data = models.CharField(max_length=10, unique=True)
|
|
|
|
objects = NKManager()
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return self.data
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return 'NKChild %s:%s' % (self.name, self.data)
|
2010-03-18 23:22:15 +08:00
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2010-03-18 23:22:15 +08: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):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '%s: Reference to %s [%s]' % (
|
2010-03-18 23:22:15 +08:00
|
|
|
self.text,
|
|
|
|
self.nk_fk,
|
|
|
|
', '.join(str(o) for o in self.nk_m2m.all())
|
|
|
|
)
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
# ome models with pathological circular dependencies
|
|
|
|
class Circle1(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle2']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
class Circle2(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle1']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
class Circle3(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle3']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
class Circle4(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle5']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
class Circle5(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle6']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
class Circle6(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.circle4']
|
|
|
|
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
class ExternalDependency(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2010-09-28 22:52:20 +08:00
|
|
|
|
2009-12-18 05:54:37 +08:00
|
|
|
def natural_key(self):
|
|
|
|
return self.name
|
|
|
|
natural_key.dependencies = ['fixtures_regress.book']
|
|
|
|
|
2010-11-12 09:44:22 +08:00
|
|
|
|
|
|
|
# Model for regression test of #11101
|
|
|
|
class Thingy(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|