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