2008-12-17 01:42:18 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2009-12-23 02:29:00 +08:00
|
|
|
import datetime
|
2009-04-19 04:29:55 +08:00
|
|
|
import tempfile
|
|
|
|
import os
|
2009-12-23 02:29:00 +08:00
|
|
|
|
2010-08-06 22:58:05 +08:00
|
|
|
from django.contrib.auth.models import User
|
2010-02-26 21:17:43 +08:00
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-14 02:51:33 +08:00
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
|
from django.db import models
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-07-19 07:54:34 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
class Section(models.Model):
|
|
|
|
"""
|
2008-08-09 02:07:33 +08:00
|
|
|
A simple section that links to articles, to test linking to related items
|
2008-07-19 07:54:34 +08:00
|
|
|
in admin views.
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-07-19 07:54:34 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
"""
|
|
|
|
A simple article to test admin views. Test backwards compatibility.
|
|
|
|
"""
|
2008-08-09 02:07:33 +08:00
|
|
|
title = models.CharField(max_length=100)
|
2008-07-19 07:54:34 +08:00
|
|
|
content = models.TextField()
|
|
|
|
date = models.DateTimeField()
|
2010-03-17 03:01:40 +08:00
|
|
|
section = models.ForeignKey(Section, null=True, blank=True)
|
2008-07-19 07:54:34 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-08-09 02:07:33 +08:00
|
|
|
return self.title
|
2009-03-10 19:19:26 +08:00
|
|
|
|
2008-10-08 22:47:01 +08:00
|
|
|
def model_year(self):
|
|
|
|
return self.date.year
|
|
|
|
model_year.admin_order_field = 'date'
|
2010-03-17 00:10:27 +08:00
|
|
|
model_year.short_description = ''
|
2008-10-08 22:47:01 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-12-16 23:04:47 +08:00
|
|
|
class Book(models.Model):
|
|
|
|
"""
|
|
|
|
A simple book that has chapters.
|
|
|
|
"""
|
2012-06-08 00:08:47 +08:00
|
|
|
name = models.CharField(max_length=100, verbose_name='¿Name?')
|
2008-12-17 01:42:18 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-12-17 01:42:18 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-12-17 01:42:18 +08:00
|
|
|
class Promo(models.Model):
|
2012-06-08 00:08:47 +08:00
|
|
|
name = models.CharField(max_length=100, verbose_name='¿Name?')
|
2008-12-17 01:42:18 +08:00
|
|
|
book = models.ForeignKey(Book)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-12-17 01:42:18 +08:00
|
|
|
return self.name
|
2008-12-16 23:04:47 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-12-16 23:04:47 +08:00
|
|
|
class Chapter(models.Model):
|
2012-06-08 00:08:47 +08:00
|
|
|
title = models.CharField(max_length=100, verbose_name='¿Title?')
|
2008-12-16 23:04:47 +08:00
|
|
|
content = models.TextField()
|
|
|
|
book = models.ForeignKey(Book)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-12-16 23:04:47 +08:00
|
|
|
return self.title
|
|
|
|
|
2008-12-17 01:42:18 +08:00
|
|
|
class Meta:
|
2010-03-02 11:28:48 +08:00
|
|
|
# Use a utf-8 bytestring to ensure it works (see #11710)
|
|
|
|
verbose_name = '¿Chapter?'
|
2008-12-17 01:42:18 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-12-17 01:42:18 +08:00
|
|
|
class ChapterXtra1(models.Model):
|
2012-06-08 00:08:47 +08:00
|
|
|
chap = models.OneToOneField(Chapter, verbose_name='¿Chap?')
|
|
|
|
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
|
2008-12-17 01:42:18 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '¿Xtra1: %s' % self.xtra
|
2008-12-17 01:42:18 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-12-17 01:42:18 +08:00
|
|
|
class ChapterXtra2(models.Model):
|
2012-06-08 00:08:47 +08:00
|
|
|
chap = models.OneToOneField(Chapter, verbose_name='¿Chap?')
|
|
|
|
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
|
2008-12-17 01:42:18 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '¿Xtra2: %s' % self.xtra
|
2008-12-17 01:42:18 +08:00
|
|
|
|
2010-11-22 03:00:40 +08:00
|
|
|
|
2011-02-19 22:05:07 +08:00
|
|
|
class RowLevelChangePermissionModel(models.Model):
|
|
|
|
name = models.CharField(max_length=100, blank=True)
|
|
|
|
|
2010-11-22 03:00:40 +08:00
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
class CustomArticle(models.Model):
|
|
|
|
content = models.TextField()
|
|
|
|
date = models.DateTimeField()
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-07-19 07:54:34 +08:00
|
|
|
class ModelWithStringPrimaryKey(models.Model):
|
2012-06-07 23:34:25 +08:00
|
|
|
string_pk = models.CharField(max_length=255, primary_key=True)
|
2008-08-09 02:07:33 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-07 23:34:25 +08:00
|
|
|
return self.string_pk
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2012-06-19 23:37:28 +08:00
|
|
|
return '/dummy/%s/' % self.string_pk
|
2008-08-09 02:07:33 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-10-22 03:03:21 +08:00
|
|
|
class Color(models.Model):
|
|
|
|
value = models.CharField(max_length=10)
|
2013-08-12 04:19:09 +08:00
|
|
|
warm = models.BooleanField(default=False)
|
2013-10-22 18:21:07 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-10-22 03:03:21 +08:00
|
|
|
return self.value
|
|
|
|
|
2012-02-10 02:59:05 +08:00
|
|
|
# we replicate Color to register with another ModelAdmin
|
|
|
|
class Color2(Color):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-10-22 03:03:21 +08:00
|
|
|
class Thing(models.Model):
|
|
|
|
title = models.CharField(max_length=20)
|
|
|
|
color = models.ForeignKey(Color, limit_choices_to={'warm': True})
|
2012-09-16 07:20:56 +08:00
|
|
|
pub_date = models.DateField(blank=True, null=True)
|
2013-10-22 18:21:07 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-10-22 03:03:21 +08:00
|
|
|
return self.title
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-28 22:08:25 +08:00
|
|
|
class Actor(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
age = models.IntegerField()
|
2013-02-26 11:27:52 +08:00
|
|
|
title = models.CharField(max_length=50, null=True, blank=True)
|
2013-10-22 18:21:07 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-01-28 22:08:25 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-28 22:08:25 +08:00
|
|
|
class Inquisition(models.Model):
|
2013-08-12 04:19:09 +08:00
|
|
|
expected = models.BooleanField(default=False)
|
2011-01-28 22:08:25 +08:00
|
|
|
leader = models.ForeignKey(Actor)
|
2011-01-28 22:08:42 +08:00
|
|
|
country = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "by %s from %s" % (self.leader, self.country)
|
2011-01-28 22:08:42 +08:00
|
|
|
|
2011-01-28 22:08:25 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-28 22:08:25 +08:00
|
|
|
class Sketch(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
inquisition = models.ForeignKey(Inquisition, limit_choices_to={'leader__name': 'Palin',
|
|
|
|
'leader__age': 27,
|
2011-01-28 22:08:42 +08:00
|
|
|
'expected': False,
|
2011-01-28 22:08:25 +08:00
|
|
|
})
|
2013-05-28 00:31:49 +08:00
|
|
|
defendant0 = models.ForeignKey(Actor, limit_choices_to={'title__isnull': False}, related_name='as_defendant0')
|
|
|
|
defendant1 = models.ForeignKey(Actor, limit_choices_to={'title__isnull': True}, related_name='as_defendant1')
|
2011-01-28 22:08:42 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-01-28 22:08:25 +08:00
|
|
|
return self.title
|
|
|
|
|
2011-01-28 22:08:42 +08:00
|
|
|
|
2009-04-01 22:14:20 +08:00
|
|
|
class Fabric(models.Model):
|
|
|
|
NG_CHOICES = (
|
|
|
|
('Textured', (
|
2013-10-20 07:33:10 +08:00
|
|
|
('x', 'Horizontal'),
|
|
|
|
('y', 'Vertical'),
|
|
|
|
)),
|
2009-04-01 22:14:20 +08:00
|
|
|
('plain', 'Smooth'),
|
|
|
|
)
|
|
|
|
surface = models.CharField(max_length=20, choices=NG_CHOICES)
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-03-18 04:51:47 +08:00
|
|
|
class Person(models.Model):
|
|
|
|
GENDER_CHOICES = (
|
|
|
|
(1, "Male"),
|
|
|
|
(2, "Female"),
|
|
|
|
)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
gender = models.IntegerField(choices=GENDER_CHOICES)
|
2011-01-03 21:56:31 +08:00
|
|
|
age = models.IntegerField(default=21)
|
2013-03-24 22:27:27 +08:00
|
|
|
alive = models.BooleanField(default=True)
|
2009-03-30 02:52:38 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-18 04:51:47 +08:00
|
|
|
return self.name
|
2009-03-30 02:52:38 +08:00
|
|
|
|
2010-02-16 20:17:37 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-03-10 19:19:26 +08:00
|
|
|
class Persona(models.Model):
|
|
|
|
"""
|
|
|
|
A simple persona associated with accounts, to test inlining of related
|
|
|
|
accounts which inherit from a common accounts class.
|
|
|
|
"""
|
2013-03-24 22:27:27 +08:00
|
|
|
name = models.CharField(blank=False, max_length=80)
|
2013-10-22 18:21:07 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-10 19:19:26 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-03-10 19:19:26 +08:00
|
|
|
class Account(models.Model):
|
|
|
|
"""
|
|
|
|
A simple, generic account encapsulating the information shared by all
|
|
|
|
types of accounts.
|
|
|
|
"""
|
2013-03-24 22:27:27 +08:00
|
|
|
username = models.CharField(blank=False, max_length=80)
|
2009-03-10 19:19:26 +08:00
|
|
|
persona = models.ForeignKey(Persona, related_name="accounts")
|
2012-06-08 00:08:47 +08:00
|
|
|
servicename = 'generic service'
|
2009-03-10 19:19:26 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-10 19:19:26 +08:00
|
|
|
return "%s: %s" % (self.servicename, self.username)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-03-10 19:19:26 +08:00
|
|
|
class FooAccount(Account):
|
|
|
|
"""A service-specific account of type Foo."""
|
2012-06-08 00:08:47 +08:00
|
|
|
servicename = 'foo'
|
2009-03-10 19:19:26 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-03-10 19:19:26 +08:00
|
|
|
class BarAccount(Account):
|
|
|
|
"""A service-specific account of type Bar."""
|
2012-06-08 00:08:47 +08:00
|
|
|
servicename = 'bar'
|
2009-03-10 19:19:26 +08:00
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-03-24 04:22:56 +08:00
|
|
|
class Subscriber(models.Model):
|
|
|
|
name = models.CharField(blank=False, max_length=80)
|
|
|
|
email = models.EmailField(blank=False, max_length=175)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-03-24 04:22:56 +08:00
|
|
|
return "%s (%s)" % (self.name, self.email)
|
|
|
|
|
|
|
|
|
|
|
|
class ExternalSubscriber(Subscriber):
|
|
|
|
pass
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-04-07 04:23:33 +08:00
|
|
|
class OldSubscriber(Subscriber):
|
|
|
|
pass
|
|
|
|
|
2009-03-18 04:51:47 +08:00
|
|
|
|
2009-03-30 02:52:38 +08:00
|
|
|
class Media(models.Model):
|
|
|
|
name = models.CharField(max_length=60)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-03-30 02:52:38 +08:00
|
|
|
class Podcast(Media):
|
|
|
|
release_date = models.DateField()
|
|
|
|
|
2011-06-03 00:18:47 +08:00
|
|
|
class Meta:
|
2013-11-03 05:02:56 +08:00
|
|
|
ordering = ('release_date',) # overridden in PodcastAdmin
|
2011-06-03 00:18:47 +08:00
|
|
|
|
2009-03-30 02:52:38 +08:00
|
|
|
|
2009-04-19 05:03:29 +08:00
|
|
|
class Vodcast(Media):
|
|
|
|
media = models.OneToOneField(Media, primary_key=True, parent_link=True)
|
|
|
|
released = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
2009-03-31 08:03:34 +08:00
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-03-31 08:03:34 +08:00
|
|
|
class Child(models.Model):
|
|
|
|
parent = models.ForeignKey(Parent, editable=False)
|
|
|
|
name = models.CharField(max_length=30, blank=True)
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-04-01 11:11:58 +08:00
|
|
|
class EmptyModel(models.Model):
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-04-01 11:11:58 +08:00
|
|
|
return "Primary key = %s" % self.id
|
|
|
|
|
2009-04-07 04:23:33 +08:00
|
|
|
|
2011-11-14 03:05:02 +08:00
|
|
|
temp_storage = FileSystemStorage(tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR']))
|
2009-04-19 04:29:55 +08:00
|
|
|
UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-04-19 04:29:55 +08:00
|
|
|
class Gallery(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-04-19 04:29:55 +08:00
|
|
|
class Picture(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
image = models.FileField(storage=temp_storage, upload_to='test_upload')
|
|
|
|
gallery = models.ForeignKey(Gallery, related_name="pictures")
|
|
|
|
|
|
|
|
|
2009-05-07 19:56:10 +08:00
|
|
|
class Language(models.Model):
|
|
|
|
iso = models.CharField(max_length=5, primary_key=True)
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
english_name = models.CharField(max_length=50)
|
|
|
|
shortlist = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('iso',)
|
|
|
|
|
|
|
|
|
2009-05-07 20:52:43 +08:00
|
|
|
# a base class for Recommender and Recommendation
|
|
|
|
class Title(models.Model):
|
|
|
|
pass
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-07 20:52:43 +08:00
|
|
|
class TitleTranslation(models.Model):
|
|
|
|
title = models.ForeignKey(Title)
|
|
|
|
text = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-07 20:52:43 +08:00
|
|
|
class Recommender(Title):
|
|
|
|
pass
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-07 20:52:43 +08:00
|
|
|
class Recommendation(Title):
|
|
|
|
recommender = models.ForeignKey(Recommender)
|
|
|
|
|
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class Collector(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class Widget(models.Model):
|
|
|
|
owner = models.ForeignKey(Collector)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class DooHickey(models.Model):
|
|
|
|
code = models.CharField(max_length=10, primary_key=True)
|
|
|
|
owner = models.ForeignKey(Collector)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class Grommet(models.Model):
|
|
|
|
code = models.AutoField(primary_key=True)
|
|
|
|
owner = models.ForeignKey(Collector)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class Whatsit(models.Model):
|
|
|
|
index = models.IntegerField(primary_key=True)
|
|
|
|
owner = models.ForeignKey(Collector)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class Doodad(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-05-09 19:40:13 +08:00
|
|
|
class FancyDoodad(Doodad):
|
|
|
|
owner = models.ForeignKey(Collector)
|
|
|
|
expensive = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-07-03 11:05:17 +08:00
|
|
|
class Category(models.Model):
|
|
|
|
collector = models.ForeignKey(Collector)
|
|
|
|
order = models.PositiveIntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('order',)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '%s:o%s' % (self.id, self.order)
|
2009-07-03 11:05:17 +08:00
|
|
|
|
2009-12-23 02:29:00 +08:00
|
|
|
|
|
|
|
class Link(models.Model):
|
|
|
|
posted = models.DateField(
|
|
|
|
default=lambda: datetime.date.today() - datetime.timedelta(days=7)
|
|
|
|
)
|
|
|
|
url = models.URLField()
|
|
|
|
post = models.ForeignKey("Post")
|
|
|
|
|
|
|
|
|
2011-04-22 20:02:25 +08:00
|
|
|
class PrePopulatedPost(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
2013-08-12 04:19:09 +08:00
|
|
|
published = models.BooleanField(default=False)
|
2011-04-22 20:02:25 +08:00
|
|
|
slug = models.SlugField()
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2011-04-22 20:02:25 +08:00
|
|
|
class PrePopulatedSubPost(models.Model):
|
|
|
|
post = models.ForeignKey(PrePopulatedPost)
|
|
|
|
subtitle = models.CharField(max_length=100)
|
|
|
|
subslug = models.SlugField()
|
|
|
|
|
|
|
|
|
2009-12-23 02:29:00 +08:00
|
|
|
class Post(models.Model):
|
2011-02-19 20:55:09 +08:00
|
|
|
title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
|
|
|
|
content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
|
|
|
|
posted = models.DateField(
|
2013-10-20 07:33:10 +08:00
|
|
|
default=datetime.date.today,
|
|
|
|
help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
|
2011-02-19 20:55:09 +08:00
|
|
|
)
|
2010-03-10 16:37:17 +08:00
|
|
|
public = models.NullBooleanField()
|
2009-12-23 02:29:00 +08:00
|
|
|
|
|
|
|
def awesomeness_level(self):
|
|
|
|
return "Very awesome."
|
|
|
|
|
2009-05-07 20:52:43 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-12-18 18:08:05 +08:00
|
|
|
class Gadget(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2009-12-18 18:08:05 +08:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class Villain(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2010-02-26 21:17:43 +08:00
|
|
|
class SuperVillain(Villain):
|
|
|
|
pass
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class FunkyTag(models.Model):
|
|
|
|
"Because we all know there's only one real use case for GFKs."
|
|
|
|
name = models.CharField(max_length=25)
|
|
|
|
content_type = models.ForeignKey(ContentType)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class Plot(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
team_leader = models.ForeignKey(Villain, related_name='lead_plots')
|
|
|
|
contact = models.ForeignKey(Villain, related_name='contact_plots')
|
|
|
|
tags = generic.GenericRelation(FunkyTag)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class PlotDetails(models.Model):
|
|
|
|
details = models.CharField(max_length=100)
|
|
|
|
plot = models.OneToOneField(Plot)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.details
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class SecretHideout(models.Model):
|
|
|
|
""" Secret! Not registered with the admin! """
|
|
|
|
location = models.CharField(max_length=100)
|
|
|
|
villain = models.ForeignKey(Villain)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.location
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class SuperSecretHideout(models.Model):
|
|
|
|
""" Secret! Not registered with the admin! """
|
|
|
|
location = models.CharField(max_length=100)
|
|
|
|
supervillain = models.ForeignKey(SuperVillain)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.location
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class CyclicOne(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
|
|
|
two = models.ForeignKey('CyclicTwo')
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-02-26 21:17:43 +08:00
|
|
|
class CyclicTwo(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
|
|
|
one = models.ForeignKey(CyclicOne)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-02-26 21:17:43 +08:00
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2010-03-21 22:23:25 +08:00
|
|
|
class Topping(models.Model):
|
2010-04-11 16:35:04 +08:00
|
|
|
name = models.CharField(max_length=20)
|
2010-03-21 22:23:25 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2010-03-21 22:23:25 +08:00
|
|
|
class Pizza(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
2013-08-29 21:39:31 +08:00
|
|
|
toppings = models.ManyToManyField('Topping', related_name='pizzas')
|
2010-03-21 22:23:25 +08:00
|
|
|
|
|
|
|
|
2010-08-06 22:58:05 +08:00
|
|
|
class Album(models.Model):
|
|
|
|
owner = models.ForeignKey(User)
|
|
|
|
title = models.CharField(max_length=30)
|
|
|
|
|
2010-12-23 11:44:38 +08:00
|
|
|
|
2011-01-13 07:30:47 +08:00
|
|
|
class Employee(Person):
|
|
|
|
code = models.CharField(max_length=20)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2011-01-13 07:30:47 +08:00
|
|
|
class WorkHour(models.Model):
|
|
|
|
datum = models.DateField()
|
|
|
|
employee = models.ForeignKey(Employee)
|
|
|
|
|
|
|
|
|
2011-01-20 08:33:32 +08:00
|
|
|
class Question(models.Model):
|
|
|
|
question = models.CharField(max_length=20)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-01-20 08:33:32 +08:00
|
|
|
class Answer(models.Model):
|
|
|
|
question = models.ForeignKey(Question, on_delete=models.PROTECT)
|
|
|
|
answer = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-01-20 08:33:32 +08:00
|
|
|
return self.answer
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2011-02-08 20:00:21 +08:00
|
|
|
class Reservation(models.Model):
|
|
|
|
start_date = models.DateTimeField()
|
|
|
|
price = models.IntegerField()
|
2011-02-19 19:48:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
DRIVER_CHOICES = (
|
2012-06-08 00:08:47 +08:00
|
|
|
('bill', 'Bill G'),
|
|
|
|
('steve', 'Steve J'),
|
2011-02-19 19:48:42 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
RESTAURANT_CHOICES = (
|
2012-06-08 00:08:47 +08:00
|
|
|
('indian', 'A Taste of India'),
|
|
|
|
('thai', 'Thai Pography'),
|
|
|
|
('pizza', 'Pizza Mama'),
|
2011-02-19 19:48:42 +08:00
|
|
|
)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2011-02-19 19:48:42 +08:00
|
|
|
class FoodDelivery(models.Model):
|
|
|
|
reference = models.CharField(max_length=100)
|
|
|
|
driver = models.CharField(max_length=100, choices=DRIVER_CHOICES, blank=True)
|
|
|
|
restaurant = models.CharField(max_length=100, choices=RESTAURANT_CHOICES, blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = (("driver", "restaurant"),)
|
|
|
|
|
|
|
|
|
2012-12-25 03:17:16 +08:00
|
|
|
@python_2_unicode_compatible
|
|
|
|
class CoverLetter(models.Model):
|
|
|
|
author = models.CharField(max_length=30)
|
|
|
|
date_written = models.DateField(null=True, blank=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.author
|
|
|
|
|
|
|
|
|
2011-02-21 07:09:25 +08:00
|
|
|
class Paper(models.Model):
|
|
|
|
title = models.CharField(max_length=30)
|
|
|
|
author = models.CharField(max_length=30, blank=True, null=True)
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2012-12-25 03:17:16 +08:00
|
|
|
class ShortMessage(models.Model):
|
|
|
|
content = models.CharField(max_length=140)
|
|
|
|
timestamp = models.DateTimeField(null=True, blank=True)
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2012-12-25 03:17:16 +08:00
|
|
|
class Telegram(models.Model):
|
|
|
|
title = models.CharField(max_length=30)
|
|
|
|
date_sent = models.DateField(null=True, blank=True)
|
2011-02-21 07:09:25 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-12-25 03:17:16 +08:00
|
|
|
return self.title
|
2011-02-21 07:09:25 +08:00
|
|
|
|
|
|
|
|
2011-03-03 21:20:45 +08:00
|
|
|
class Story(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
content = models.TextField()
|
|
|
|
|
|
|
|
|
|
|
|
class OtherStory(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
content = models.TextField()
|
|
|
|
|
2011-02-19 19:48:42 +08:00
|
|
|
|
2011-06-03 19:54:29 +08:00
|
|
|
class ComplexSortedPerson(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
age = models.PositiveIntegerField()
|
|
|
|
is_employee = models.NullBooleanField()
|
|
|
|
|
2013-05-19 16:52:29 +08:00
|
|
|
|
|
|
|
class PluggableSearchPerson(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
age = models.PositiveIntegerField()
|
|
|
|
|
|
|
|
|
2011-11-22 17:14:09 +08:00
|
|
|
class PrePopulatedPostLargeSlug(models.Model):
|
|
|
|
"""
|
|
|
|
Regression test for #15938: a large max_length for the slugfield must not
|
|
|
|
be localized in prepopulated_fields_js.html or it might end up breaking
|
|
|
|
the javascript (ie, using THOUSAND_SEPARATOR ends up with maxLength=1,000)
|
|
|
|
"""
|
|
|
|
title = models.CharField(max_length=100)
|
2013-08-12 04:19:09 +08:00
|
|
|
published = models.BooleanField(default=False)
|
2011-10-26 13:33:17 +08:00
|
|
|
slug = models.SlugField(max_length=1000)
|
2011-11-22 17:14:09 +08:00
|
|
|
|
|
|
|
class AdminOrderedField(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
|
|
|
|
|
|
|
class AdminOrderedModelMethod(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
2013-10-22 18:21:07 +08:00
|
|
|
|
2011-11-22 17:14:09 +08:00
|
|
|
def some_order(self):
|
|
|
|
return self.order
|
|
|
|
some_order.admin_order_field = 'order'
|
|
|
|
|
|
|
|
class AdminOrderedAdminMethod(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
|
|
|
|
|
|
|
class AdminOrderedCallable(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
2011-12-19 22:59:14 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-12-19 22:59:14 +08:00
|
|
|
class Report(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-12-19 22:59:14 +08:00
|
|
|
return self.title
|
2012-02-20 00:42:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
class MainPrepopulated(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
pubdate = models.DateField()
|
|
|
|
status = models.CharField(
|
|
|
|
max_length=20,
|
|
|
|
choices=(('option one', 'Option One'),
|
|
|
|
('option two', 'Option Two')))
|
2013-07-30 15:21:08 +08:00
|
|
|
slug1 = models.SlugField(blank=True)
|
|
|
|
slug2 = models.SlugField(blank=True)
|
2012-02-20 00:42:12 +08:00
|
|
|
|
|
|
|
class RelatedPrepopulated(models.Model):
|
|
|
|
parent = models.ForeignKey(MainPrepopulated)
|
|
|
|
name = models.CharField(max_length=75)
|
|
|
|
pubdate = models.DateField()
|
|
|
|
status = models.CharField(
|
|
|
|
max_length=20,
|
|
|
|
choices=(('option one', 'Option One'),
|
|
|
|
('option two', 'Option Two')))
|
|
|
|
slug1 = models.SlugField(max_length=50)
|
2012-03-03 10:13:35 +08:00
|
|
|
slug2 = models.SlugField(max_length=60)
|
|
|
|
|
|
|
|
|
|
|
|
class UnorderedObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model without any defined `Meta.ordering`.
|
|
|
|
Refs #16819.
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
bool = models.BooleanField(default=True)
|
2012-07-22 09:10:24 +08:00
|
|
|
|
|
|
|
class UndeletableObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model whose show_delete in admin change_view has been disabled
|
|
|
|
Refs #10057.
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=255)
|
2012-09-08 23:18:08 +08:00
|
|
|
|
2013-08-18 06:05:13 +08:00
|
|
|
class UnchangeableObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model whose change_view is disabled in admin
|
|
|
|
Refs #20640.
|
|
|
|
"""
|
|
|
|
|
2012-11-18 05:53:31 +08:00
|
|
|
class UserMessenger(models.Model):
|
|
|
|
"""
|
|
|
|
Dummy class for testing message_user functions on ModelAdmin
|
|
|
|
"""
|
2012-09-08 23:18:08 +08:00
|
|
|
|
|
|
|
class Simple(models.Model):
|
|
|
|
"""
|
|
|
|
Simple model with nothing on it for use in testing
|
|
|
|
"""
|
2012-11-26 06:13:22 +08:00
|
|
|
|
|
|
|
class Choice(models.Model):
|
2012-12-05 04:49:02 +08:00
|
|
|
choice = models.IntegerField(blank=True, null=True,
|
|
|
|
choices=((1, 'Yes'), (0, 'No'), (None, 'No opinion')))
|
2013-09-07 04:28:48 +08:00
|
|
|
|
|
|
|
class _Manager(models.Manager):
|
|
|
|
def get_queryset(self):
|
|
|
|
return super(_Manager, self).get_queryset().filter(pk__gt=1)
|
|
|
|
|
|
|
|
class FilteredManager(models.Model):
|
|
|
|
def __str__(self):
|
|
|
|
return "PK=%d" % self.pk
|
|
|
|
|
|
|
|
pk_gt_1 = _Manager()
|
|
|
|
objects = models.Manager()
|
2013-02-24 01:57:48 +08:00
|
|
|
|
|
|
|
class EmptyModelVisible(models.Model):
|
|
|
|
""" See ticket #11277. """
|
|
|
|
|
|
|
|
class EmptyModelHidden(models.Model):
|
|
|
|
""" See ticket #11277. """
|
|
|
|
|
|
|
|
class EmptyModelMixin(models.Model):
|
|
|
|
""" See ticket #11277. """
|
2013-10-24 23:28:09 +08:00
|
|
|
|
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class City(models.Model):
|
|
|
|
state = models.ForeignKey(State)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Restaurant(models.Model):
|
|
|
|
city = models.ForeignKey(City)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Worker(models.Model):
|
|
|
|
work_at = models.ForeignKey(Restaurant)
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
surname = models.CharField(max_length=50)
|