2009-12-23 02:29:00 +08:00
|
|
|
import datetime
|
2009-04-19 04:29:55 +08:00
|
|
|
import os
|
2015-01-28 20:35:27 +08:00
|
|
|
import tempfile
|
2016-01-07 17:07:15 +08:00
|
|
|
import uuid
|
2009-12-23 02:29:00 +08:00
|
|
|
|
2010-08-06 22:58:05 +08:00
|
|
|
from django.contrib.auth.models import User
|
2014-01-22 14:43:33 +08:00
|
|
|
from django.contrib.contenttypes.fields import (
|
2015-01-28 20:35:27 +08:00
|
|
|
GenericForeignKey, GenericRelation,
|
2014-01-22 14:43:33 +08:00
|
|
|
)
|
2010-02-26 21:17:43 +08:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2015-04-25 09:31:26 +08:00
|
|
|
from django.core.exceptions import ValidationError
|
2011-10-14 02:51:33 +08:00
|
|
|
from django.core.files.storage import FileSystemStorage
|
|
|
|
from django.db import models
|
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)
|
|
|
|
|
2016-01-08 23:21:27 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2015-03-08 18:50:32 +08:00
|
|
|
@property
|
|
|
|
def name_property(self):
|
|
|
|
"""
|
|
|
|
A property that simply returns the name. Used to test #24461
|
|
|
|
"""
|
|
|
|
return self.name
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
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()
|
2015-07-22 22:43:21 +08:00
|
|
|
section = models.ForeignKey(Section, models.CASCADE, null=True, blank=True)
|
2015-12-10 15:06:01 +08:00
|
|
|
another_section = models.ForeignKey(Section, models.CASCADE, null=True, blank=True, related_name='+')
|
2015-07-22 22:43:21 +08:00
|
|
|
sub_section = models.ForeignKey(Section, models.SET_NULL, null=True, blank=True, related_name='+')
|
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
|
|
|
|
2014-01-23 10:13:59 +08:00
|
|
|
def model_year_reversed(self):
|
|
|
|
return self.date.year
|
|
|
|
model_year_reversed.admin_order_field = '-date'
|
|
|
|
model_year_reversed.short_description = ''
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
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
|
|
|
|
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?')
|
2015-07-22 22:43:21 +08:00
|
|
|
book = models.ForeignKey(Book, models.CASCADE)
|
2017-06-05 02:10:48 +08:00
|
|
|
author = models.ForeignKey(User, models.SET_NULL, blank=True, null=True)
|
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
|
2008-12-16 23:04:47 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
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()
|
2015-07-22 22:43:21 +08:00
|
|
|
book = models.ForeignKey(Book, models.CASCADE)
|
2008-12-16 23:04:47 +08:00
|
|
|
|
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
|
|
|
|
2018-12-28 08:34:14 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2008-12-17 01:42:18 +08:00
|
|
|
class ChapterXtra1(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
chap = models.OneToOneField(Chapter, models.CASCADE, verbose_name='¿Chap?')
|
2012-06-08 00:08:47 +08:00
|
|
|
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
|
2017-06-05 02:10:48 +08:00
|
|
|
guest_author = models.ForeignKey(User, models.SET_NULL, blank=True, null=True)
|
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
|
|
|
|
2008-12-17 01:42:18 +08:00
|
|
|
class ChapterXtra2(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
chap = models.OneToOneField(Chapter, models.CASCADE, verbose_name='¿Chap?')
|
2012-06-08 00:08:47 +08:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
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
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2008-10-22 03:03:21 +08:00
|
|
|
class Thing(models.Model):
|
|
|
|
title = models.CharField(max_length=20)
|
2015-07-22 22:43:21 +08:00
|
|
|
color = models.ForeignKey(Color, models.CASCADE, 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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
2015-07-22 22:43:21 +08:00
|
|
|
leader = models.ForeignKey(Actor, models.CASCADE)
|
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
|
|
|
|
|
|
|
class Sketch(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
inquisition = models.ForeignKey(
|
|
|
|
Inquisition,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to={
|
|
|
|
'leader__name': 'Palin',
|
|
|
|
'leader__age': 27,
|
|
|
|
'expected': False,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
defendant0 = models.ForeignKey(
|
|
|
|
Actor,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to={'title__isnull': False},
|
|
|
|
related_name='as_defendant0',
|
|
|
|
)
|
|
|
|
defendant1 = models.ForeignKey(
|
|
|
|
Actor,
|
|
|
|
models.CASCADE,
|
|
|
|
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
|
|
|
|
2014-02-02 03:23:31 +08:00
|
|
|
def today_callable_dict():
|
|
|
|
return {"last_action__gte": datetime.datetime.today()}
|
|
|
|
|
|
|
|
|
|
|
|
def today_callable_q():
|
|
|
|
return models.Q(last_action__gte=datetime.datetime.today())
|
|
|
|
|
|
|
|
|
|
|
|
class Character(models.Model):
|
|
|
|
username = models.CharField(max_length=100)
|
|
|
|
last_action = models.DateTimeField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.username
|
|
|
|
|
|
|
|
|
|
|
|
class StumpJoke(models.Model):
|
|
|
|
variation = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
most_recently_fooled = models.ForeignKey(
|
|
|
|
Character,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to=today_callable_dict,
|
|
|
|
related_name="+",
|
|
|
|
)
|
2014-02-02 03:23:31 +08:00
|
|
|
has_fooled_today = models.ManyToManyField(Character, limit_choices_to=today_callable_q, related_name="+")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.variation
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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)
|
2015-07-22 22:43:21 +08:00
|
|
|
persona = models.ForeignKey(Persona, models.CASCADE, 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
|
|
|
|
|
|
|
|
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):
|
2015-07-22 22:43:21 +08:00
|
|
|
media = models.OneToOneField(Media, models.CASCADE, primary_key=True, parent_link=True)
|
2009-04-19 05:03:29 +08:00
|
|
|
released = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
|
2009-03-31 08:03:34 +08:00
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
2015-04-25 09:31:26 +08:00
|
|
|
def clean(self):
|
|
|
|
if self.name == '_invalid':
|
|
|
|
raise ValidationError('invalid')
|
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2009-03-31 08:03:34 +08:00
|
|
|
class Child(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(Parent, models.CASCADE, editable=False)
|
2009-03-31 08:03:34 +08:00
|
|
|
name = models.CharField(max_length=30, blank=True)
|
|
|
|
|
2015-04-25 09:31:26 +08:00
|
|
|
def clean(self):
|
|
|
|
if self.name == '_invalid':
|
|
|
|
raise ValidationError('invalid')
|
|
|
|
|
2009-03-31 08:03:34 +08:00
|
|
|
|
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
|
|
|
|
2015-02-22 01:56:36 +08:00
|
|
|
temp_storage = FileSystemStorage(tempfile.mkdtemp())
|
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')
|
2015-07-22 22:43:21 +08:00
|
|
|
gallery = models.ForeignKey(Gallery, models.CASCADE, related_name="pictures")
|
2009-04-19 04:29:55 +08:00
|
|
|
|
|
|
|
|
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):
|
2015-07-22 22:43:21 +08:00
|
|
|
title = models.ForeignKey(Title, models.CASCADE)
|
2009-05-07 20:52:43 +08:00
|
|
|
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):
|
2016-08-05 23:19:09 +08:00
|
|
|
the_recommender = models.ForeignKey(Recommender, models.CASCADE)
|
2009-05-07 20:52:43 +08:00
|
|
|
|
|
|
|
|
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):
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(Collector, models.CASCADE)
|
2009-05-09 19:40:13 +08:00
|
|
|
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)
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(Collector, models.CASCADE)
|
2009-05-09 19:40:13 +08:00
|
|
|
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)
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(Collector, models.CASCADE)
|
2009-05-09 19:40:13 +08:00
|
|
|
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)
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(Collector, models.CASCADE)
|
2009-05-09 19:40:13 +08:00
|
|
|
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):
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(Collector, models.CASCADE)
|
2009-05-09 19:40:13 +08:00
|
|
|
expensive = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
|
2009-07-03 11:05:17 +08:00
|
|
|
class Category(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
collector = models.ForeignKey(Collector, models.CASCADE)
|
2009-07-03 11:05:17 +08:00
|
|
|
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
|
|
|
|
2015-07-16 09:18:07 +08:00
|
|
|
def link_posted_default():
|
|
|
|
return datetime.date.today() - datetime.timedelta(days=7)
|
|
|
|
|
|
|
|
|
2009-12-23 02:29:00 +08:00
|
|
|
class Link(models.Model):
|
2015-07-16 09:18:07 +08:00
|
|
|
posted = models.DateField(default=link_posted_default)
|
2009-12-23 02:29:00 +08:00
|
|
|
url = models.URLField()
|
2015-07-22 22:43:21 +08:00
|
|
|
post = models.ForeignKey("Post", models.CASCADE)
|
2015-12-25 05:32:53 +08:00
|
|
|
readonly_link_content = models.TextField()
|
2009-12-23 02:29:00 +08:00
|
|
|
|
|
|
|
|
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):
|
2015-07-22 22:43:21 +08:00
|
|
|
post = models.ForeignKey(PrePopulatedPost, models.CASCADE)
|
2011-04-22 20:02:25 +08:00
|
|
|
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 ŠĐĆŽćžšđ)")
|
2015-12-25 05:32:53 +08:00
|
|
|
readonly_content = models.TextField()
|
2011-02-19 20:55:09 +08:00
|
|
|
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
|
|
|
)
|
2017-05-06 22:56:28 +08:00
|
|
|
public = models.BooleanField(null=True, blank=True)
|
2009-12-23 02:29:00 +08:00
|
|
|
|
|
|
|
def awesomeness_level(self):
|
|
|
|
return "Very awesome."
|
|
|
|
|
2009-05-07 20:52:43 +08:00
|
|
|
|
2014-02-19 06:44:33 +08:00
|
|
|
# Proxy model to test overridden fields attrs on Post model so as not to
|
|
|
|
# interfere with other tests.
|
|
|
|
class FieldOverridePost(Post):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
2015-07-22 22:43:21 +08:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2010-02-26 21:17:43 +08:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 14:43:33 +08:00
|
|
|
content_object = GenericForeignKey('content_type', 'object_id')
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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 Plot(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
team_leader = models.ForeignKey(Villain, models.CASCADE, related_name='lead_plots')
|
|
|
|
contact = models.ForeignKey(Villain, models.CASCADE, related_name='contact_plots')
|
2014-01-22 14:43:33 +08:00
|
|
|
tags = GenericRelation(FunkyTag)
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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 PlotDetails(models.Model):
|
|
|
|
details = models.CharField(max_length=100)
|
2016-01-10 04:15:21 +08:00
|
|
|
plot = models.OneToOneField(Plot, models.CASCADE, null=True, blank=True)
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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
|
|
|
|
2016-01-10 04:15:21 +08:00
|
|
|
class PlotProxy(Plot):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2010-02-26 21:17:43 +08:00
|
|
|
class SecretHideout(models.Model):
|
|
|
|
""" Secret! Not registered with the admin! """
|
|
|
|
location = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
villain = models.ForeignKey(Villain, models.CASCADE)
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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
|
|
|
|
2010-02-26 21:17:43 +08:00
|
|
|
class SuperSecretHideout(models.Model):
|
|
|
|
""" Secret! Not registered with the admin! """
|
|
|
|
location = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
supervillain = models.ForeignKey(SuperVillain, models.CASCADE)
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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
|
|
|
|
2015-08-28 04:13:24 +08:00
|
|
|
class Bookmark(models.Model):
|
|
|
|
name = models.CharField(max_length=60)
|
|
|
|
tag = GenericRelation(FunkyTag, related_query_name='bookmark')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2010-02-26 21:17:43 +08:00
|
|
|
class CyclicOne(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
2015-07-22 22:43:21 +08:00
|
|
|
two = models.ForeignKey('CyclicTwo', models.CASCADE)
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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 CyclicTwo(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
2015-07-22 22:43:21 +08:00
|
|
|
one = models.ForeignKey(CyclicOne, models.CASCADE)
|
2010-02-26 21:17:43 +08:00
|
|
|
|
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
|
|
|
|
2016-09-11 23:19:56 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2017-04-05 11:54:46 +08:00
|
|
|
# Pizza's ModelAdmin has readonly_fields = ['toppings'].
|
|
|
|
# toppings is editable for this model's admin.
|
|
|
|
class ReadablePizza(Pizza):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2017-08-23 07:48:55 +08:00
|
|
|
# No default permissions are created for this model and both name and toppings
|
|
|
|
# are readonly for this model's admin.
|
|
|
|
class ReadOnlyPizza(Pizza):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
default_permissions = ()
|
|
|
|
|
|
|
|
|
2010-08-06 22:58:05 +08:00
|
|
|
class Album(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(User, models.SET_NULL, null=True, blank=True)
|
2010-08-06 22:58:05 +08:00
|
|
|
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()
|
2015-07-22 22:43:21 +08:00
|
|
|
employee = models.ForeignKey(Employee, models.CASCADE)
|
2011-01-13 07:30:47 +08:00
|
|
|
|
|
|
|
|
2011-01-20 08:33:32 +08:00
|
|
|
class Question(models.Model):
|
|
|
|
question = models.CharField(max_length=20)
|
2016-05-06 01:52:54 +08:00
|
|
|
posted = models.DateField(default=datetime.date.today)
|
2017-02-24 23:22:25 +08:00
|
|
|
expires = models.DateTimeField(null=True, blank=True)
|
2017-05-10 20:48:57 +08:00
|
|
|
related_questions = models.ManyToManyField('self')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.question
|
2011-01-20 08:33:32 +08:00
|
|
|
|
2011-09-21 02:16:49 +08:00
|
|
|
|
2011-01-20 08:33:32 +08:00
|
|
|
class Answer(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
question = models.ForeignKey(Question, models.PROTECT)
|
2011-01-20 08:33:32 +08:00
|
|
|
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
|
|
|
|
2017-02-24 23:22:25 +08:00
|
|
|
class Answer2(Answer):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
class FoodDelivery(models.Model):
|
2018-12-10 22:28:49 +08:00
|
|
|
DRIVER_CHOICES = (
|
|
|
|
('bill', 'Bill G'),
|
|
|
|
('steve', 'Steve J'),
|
|
|
|
)
|
|
|
|
RESTAURANT_CHOICES = (
|
|
|
|
('indian', 'A Taste of India'),
|
|
|
|
('thai', 'Thai Pography'),
|
|
|
|
('pizza', 'Pizza Mama'),
|
|
|
|
)
|
2011-02-19 19:48:42 +08:00
|
|
|
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
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
2017-05-06 22:56:28 +08:00
|
|
|
is_employee = models.BooleanField(null=True)
|
2011-06-03 19:54:29 +08:00
|
|
|
|
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)
|
2014-10-19 08:27:31 +08:00
|
|
|
# `db_index=False` because MySQL cannot index large CharField (#21196).
|
|
|
|
slug = models.SlugField(max_length=1000, db_index=False)
|
2011-11-22 17:14:09 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-11-22 17:14:09 +08:00
|
|
|
class AdminOrderedField(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-11-22 17:14:09 +08:00
|
|
|
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'
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-11-22 17:14:09 +08:00
|
|
|
class AdminOrderedAdminMethod(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-11-22 17:14:09 +08:00
|
|
|
class AdminOrderedCallable(models.Model):
|
|
|
|
order = models.IntegerField()
|
|
|
|
stuff = models.CharField(max_length=200)
|
2011-12-19 22:59:14 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
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)
|
2015-04-16 06:28:49 +08:00
|
|
|
slug3 = models.SlugField(blank=True, allow_unicode=True)
|
2012-02-20 00:42:12 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-02-20 00:42:12 +08:00
|
|
|
class RelatedPrepopulated(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(MainPrepopulated, models.CASCADE)
|
2012-02-20 00:42:12 +08:00
|
|
|
name = models.CharField(max_length=75)
|
2017-05-10 20:48:57 +08:00
|
|
|
fk = models.ForeignKey('self', models.CASCADE, blank=True, null=True)
|
|
|
|
m2m = models.ManyToManyField('self', blank=True)
|
2012-02-20 00:42:12 +08:00
|
|
|
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
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
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-11-03 12:36:09 +08:00
|
|
|
|
2013-08-18 06:05:13 +08:00
|
|
|
class UnchangeableObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model whose change_view is disabled in admin
|
|
|
|
Refs #20640.
|
|
|
|
"""
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
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
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
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
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-11-26 06:13:22 +08:00
|
|
|
class Choice(models.Model):
|
2016-04-08 10:04:45 +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
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-11-15 10:26:19 +08:00
|
|
|
class ParentWithDependentChildren(models.Model):
|
|
|
|
"""
|
|
|
|
Issue #20522
|
|
|
|
Model where the validation of child foreign-key relationships depends
|
|
|
|
on validation of the parent
|
|
|
|
"""
|
|
|
|
some_required_info = models.PositiveIntegerField()
|
|
|
|
family_name = models.CharField(max_length=255, blank=False)
|
|
|
|
|
|
|
|
|
|
|
|
class DependentChild(models.Model):
|
|
|
|
"""
|
|
|
|
Issue #20522
|
|
|
|
Model that depends on validation of the parent class for one of its
|
|
|
|
fields to validate during clean
|
|
|
|
"""
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(ParentWithDependentChildren, models.CASCADE)
|
2013-11-15 10:26:19 +08:00
|
|
|
family_name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
|
2013-09-07 04:28:48 +08:00
|
|
|
class _Manager(models.Manager):
|
|
|
|
def get_queryset(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
return super().get_queryset().filter(pk__gt=1)
|
2013-09-07 04:28:48 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-09-07 04:28:48 +08:00
|
|
|
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
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-02-24 01:57:48 +08:00
|
|
|
class EmptyModelVisible(models.Model):
|
|
|
|
""" See ticket #11277. """
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-02-24 01:57:48 +08:00
|
|
|
class EmptyModelHidden(models.Model):
|
|
|
|
""" See ticket #11277. """
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-02-24 01:57:48 +08:00
|
|
|
class EmptyModelMixin(models.Model):
|
|
|
|
""" See ticket #11277. """
|
2013-10-24 23:28:09 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-10-24 23:28:09 +08:00
|
|
|
class State(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-10-24 23:28:09 +08:00
|
|
|
class City(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
state = models.ForeignKey(State, models.CASCADE)
|
2013-10-24 23:28:09 +08:00
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2013-11-21 17:26:49 +08:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return '/dummy/%s/' % self.pk
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-10-24 23:28:09 +08:00
|
|
|
class Restaurant(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
city = models.ForeignKey(City, models.CASCADE)
|
2013-10-24 23:28:09 +08:00
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
2013-11-21 17:26:49 +08:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return '/dummy/%s/' % self.pk
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-10-24 23:28:09 +08:00
|
|
|
class Worker(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
work_at = models.ForeignKey(Restaurant, models.CASCADE)
|
2013-10-24 23:28:09 +08:00
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
surname = models.CharField(max_length=50)
|
2014-08-21 23:55:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Models for #23329
|
|
|
|
class ReferencedByParent(models.Model):
|
2014-11-16 23:42:09 +08:00
|
|
|
name = models.CharField(max_length=20, unique=True)
|
2014-08-21 23:55:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ParentWithFK(models.Model):
|
2014-11-16 23:42:09 +08:00
|
|
|
fk = models.ForeignKey(
|
2015-07-22 22:43:21 +08:00
|
|
|
ReferencedByParent,
|
|
|
|
models.CASCADE,
|
|
|
|
to_field='name',
|
|
|
|
related_name='hidden+',
|
2014-11-16 23:42:09 +08:00
|
|
|
)
|
2014-08-21 23:55:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ChildOfReferer(ParentWithFK):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-09-05 05:04:53 +08:00
|
|
|
# Models for #23431
|
2016-08-05 22:20:38 +08:00
|
|
|
class InlineReferer(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-09-05 05:04:53 +08:00
|
|
|
class ReferencedByInline(models.Model):
|
2014-11-16 23:42:09 +08:00
|
|
|
name = models.CharField(max_length=20, unique=True)
|
2014-09-05 05:04:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
class InlineReference(models.Model):
|
2016-08-05 22:20:38 +08:00
|
|
|
referer = models.ForeignKey(InlineReferer, models.CASCADE)
|
2014-11-16 23:42:09 +08:00
|
|
|
fk = models.ForeignKey(
|
2015-07-22 22:43:21 +08:00
|
|
|
ReferencedByInline,
|
|
|
|
models.CASCADE,
|
|
|
|
to_field='name',
|
|
|
|
related_name='hidden+',
|
2014-11-16 23:42:09 +08:00
|
|
|
)
|
2014-09-05 05:04:53 +08:00
|
|
|
|
|
|
|
|
2014-10-06 02:06:51 +08:00
|
|
|
class Recipe(models.Model):
|
2014-11-26 03:27:46 +08:00
|
|
|
rname = models.CharField(max_length=20, unique=True)
|
2014-10-06 02:06:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Ingredient(models.Model):
|
2014-11-26 03:27:46 +08:00
|
|
|
iname = models.CharField(max_length=20, unique=True)
|
|
|
|
recipes = models.ManyToManyField(Recipe, through='RecipeIngredient')
|
|
|
|
|
|
|
|
|
|
|
|
class RecipeIngredient(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
ingredient = models.ForeignKey(Ingredient, models.CASCADE, to_field='iname')
|
|
|
|
recipe = models.ForeignKey(Recipe, models.CASCADE, to_field='rname')
|
2014-11-16 23:42:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Model for #23839
|
|
|
|
class NotReferenced(models.Model):
|
|
|
|
# Don't point any FK at this model.
|
|
|
|
pass
|
2014-11-28 02:34:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Models for #23934
|
|
|
|
class ExplicitlyProvidedPK(models.Model):
|
|
|
|
name = models.IntegerField(primary_key=True)
|
|
|
|
|
|
|
|
|
|
|
|
class ImplicitlyGeneratedPK(models.Model):
|
|
|
|
name = models.IntegerField(unique=True)
|
2015-10-28 23:25:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Models for #25622
|
|
|
|
class ReferencedByGenRel(models.Model):
|
|
|
|
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = GenericForeignKey('content_type', 'object_id')
|
|
|
|
|
|
|
|
|
|
|
|
class GenRelReference(models.Model):
|
|
|
|
references = GenericRelation(ReferencedByGenRel)
|
2016-01-07 17:07:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ParentWithUUIDPK(models.Model):
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.id)
|
|
|
|
|
|
|
|
|
|
|
|
class RelatedWithUUIDPKModel(models.Model):
|
2016-01-09 08:39:05 +08:00
|
|
|
parent = models.ForeignKey(ParentWithUUIDPK, on_delete=models.SET_NULL, null=True, blank=True)
|
2017-05-10 20:48:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Authorship(models.Model):
|
|
|
|
book = models.ForeignKey(Book, models.CASCADE)
|
|
|
|
author = models.ForeignKey(Author, models.CASCADE)
|
2019-01-16 23:07:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
class UserProxy(User):
|
|
|
|
"""Proxy a model with a different app_label."""
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|