1
# -*- coding: utf-8 -*-
2
from __future__ import unicode_literals
8
from django.contrib.auth.models import User
9
from django.contrib.contenttypes import generic
10
from django.contrib.contenttypes.models import ContentType
11
from django.core.files.storage import FileSystemStorage
12
from django.db import models
13
from django.utils.encoding import python_2_unicode_compatible
16
class Section(models.Model):
18
A simple section that links to articles, to test linking to related items
21
name = models.CharField(max_length=100)
24
@python_2_unicode_compatible
25
class Article(models.Model):
27
A simple article to test admin views. Test backwards compatibility.
29
title = models.CharField(max_length=100)
30
content = models.TextField()
31
date = models.DateTimeField()
32
section = models.ForeignKey(Section, null=True, blank=True)
39
model_year.admin_order_field = 'date'
40
model_year.short_description = ''
43
@python_2_unicode_compatible
44
class Book(models.Model):
46
A simple book that has chapters.
48
name = models.CharField(max_length=100, verbose_name='¿Name?')
54
@python_2_unicode_compatible
55
class Promo(models.Model):
56
name = models.CharField(max_length=100, verbose_name='¿Name?')
57
book = models.ForeignKey(Book)
63
@python_2_unicode_compatible
64
class Chapter(models.Model):
65
title = models.CharField(max_length=100, verbose_name='¿Title?')
66
content = models.TextField()
67
book = models.ForeignKey(Book)
73
# Use a utf-8 bytestring to ensure it works (see #11710)
74
verbose_name = '¿Chapter?'
77
@python_2_unicode_compatible
78
class ChapterXtra1(models.Model):
79
chap = models.OneToOneField(Chapter, verbose_name='¿Chap?')
80
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
83
return '¿Xtra1: %s' % self.xtra
86
@python_2_unicode_compatible
87
class ChapterXtra2(models.Model):
88
chap = models.OneToOneField(Chapter, verbose_name='¿Chap?')
89
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
92
return '¿Xtra2: %s' % self.xtra
95
class RowLevelChangePermissionModel(models.Model):
96
name = models.CharField(max_length=100, blank=True)
99
class CustomArticle(models.Model):
100
content = models.TextField()
101
date = models.DateTimeField()
104
@python_2_unicode_compatible
105
class ModelWithStringPrimaryKey(models.Model):
106
string_pk = models.CharField(max_length=255, primary_key=True)
109
return self.string_pk
111
def get_absolute_url(self):
112
return '/dummy/%s/' % self.string_pk
115
@python_2_unicode_compatible
116
class Color(models.Model):
117
value = models.CharField(max_length=10)
118
warm = models.BooleanField()
122
# we replicate Color to register with another ModelAdmin
127
@python_2_unicode_compatible
128
class Thing(models.Model):
129
title = models.CharField(max_length=20)
130
color = models.ForeignKey(Color, limit_choices_to={'warm': True})
131
pub_date = models.DateField(blank=True, null=True)
136
@python_2_unicode_compatible
137
class Actor(models.Model):
138
name = models.CharField(max_length=50)
139
age = models.IntegerField()
144
@python_2_unicode_compatible
145
class Inquisition(models.Model):
146
expected = models.BooleanField()
147
leader = models.ForeignKey(Actor)
148
country = models.CharField(max_length=20)
151
return "by %s from %s" % (self.leader, self.country)
154
@python_2_unicode_compatible
155
class Sketch(models.Model):
156
title = models.CharField(max_length=100)
157
inquisition = models.ForeignKey(Inquisition, limit_choices_to={'leader__name': 'Palin',
166
class Fabric(models.Model):
175
surface = models.CharField(max_length=20, choices=NG_CHOICES)
178
@python_2_unicode_compatible
179
class Person(models.Model):
184
name = models.CharField(max_length=100)
185
gender = models.IntegerField(choices=GENDER_CHOICES)
186
age = models.IntegerField(default=21)
187
alive = models.BooleanField()
193
@python_2_unicode_compatible
194
class Persona(models.Model):
196
A simple persona associated with accounts, to test inlining of related
197
accounts which inherit from a common accounts class.
199
name = models.CharField(blank=False, max_length=80)
204
@python_2_unicode_compatible
205
class Account(models.Model):
207
A simple, generic account encapsulating the information shared by all
210
username = models.CharField(blank=False, max_length=80)
211
persona = models.ForeignKey(Persona, related_name="accounts")
212
servicename = 'generic service'
215
return "%s: %s" % (self.servicename, self.username)
218
class FooAccount(Account):
219
"""A service-specific account of type Foo."""
223
class BarAccount(Account):
224
"""A service-specific account of type Bar."""
228
@python_2_unicode_compatible
229
class Subscriber(models.Model):
230
name = models.CharField(blank=False, max_length=80)
231
email = models.EmailField(blank=False, max_length=175)
234
return "%s (%s)" % (self.name, self.email)
237
class ExternalSubscriber(Subscriber):
241
class OldSubscriber(Subscriber):
245
class Media(models.Model):
246
name = models.CharField(max_length=60)
249
class Podcast(Media):
250
release_date = models.DateField()
253
ordering = ('release_date',) # overridden in PodcastAdmin
256
class Vodcast(Media):
257
media = models.OneToOneField(Media, primary_key=True, parent_link=True)
258
released = models.BooleanField(default=False)
261
class Parent(models.Model):
262
name = models.CharField(max_length=128)
265
class Child(models.Model):
266
parent = models.ForeignKey(Parent, editable=False)
267
name = models.CharField(max_length=30, blank=True)
270
@python_2_unicode_compatible
271
class EmptyModel(models.Model):
273
return "Primary key = %s" % self.id
276
temp_storage = FileSystemStorage(tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR']))
277
UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')
280
class Gallery(models.Model):
281
name = models.CharField(max_length=100)
284
class Picture(models.Model):
285
name = models.CharField(max_length=100)
286
image = models.FileField(storage=temp_storage, upload_to='test_upload')
287
gallery = models.ForeignKey(Gallery, related_name="pictures")
290
class Language(models.Model):
291
iso = models.CharField(max_length=5, primary_key=True)
292
name = models.CharField(max_length=50)
293
english_name = models.CharField(max_length=50)
294
shortlist = models.BooleanField(default=False)
300
# a base class for Recommender and Recommendation
301
class Title(models.Model):
305
class TitleTranslation(models.Model):
306
title = models.ForeignKey(Title)
307
text = models.CharField(max_length=100)
310
class Recommender(Title):
314
class Recommendation(Title):
315
recommender = models.ForeignKey(Recommender)
318
class Collector(models.Model):
319
name = models.CharField(max_length=100)
322
class Widget(models.Model):
323
owner = models.ForeignKey(Collector)
324
name = models.CharField(max_length=100)
327
class DooHickey(models.Model):
328
code = models.CharField(max_length=10, primary_key=True)
329
owner = models.ForeignKey(Collector)
330
name = models.CharField(max_length=100)
333
class Grommet(models.Model):
334
code = models.AutoField(primary_key=True)
335
owner = models.ForeignKey(Collector)
336
name = models.CharField(max_length=100)
339
class Whatsit(models.Model):
340
index = models.IntegerField(primary_key=True)
341
owner = models.ForeignKey(Collector)
342
name = models.CharField(max_length=100)
345
class Doodad(models.Model):
346
name = models.CharField(max_length=100)
349
class FancyDoodad(Doodad):
350
owner = models.ForeignKey(Collector)
351
expensive = models.BooleanField(default=True)
354
@python_2_unicode_compatible
355
class Category(models.Model):
356
collector = models.ForeignKey(Collector)
357
order = models.PositiveIntegerField()
360
ordering = ('order',)
363
return '%s:o%s' % (self.id, self.order)
366
class Link(models.Model):
367
posted = models.DateField(
368
default=lambda: datetime.date.today() - datetime.timedelta(days=7)
370
url = models.URLField()
371
post = models.ForeignKey("Post")
374
class PrePopulatedPost(models.Model):
375
title = models.CharField(max_length=100)
376
published = models.BooleanField()
377
slug = models.SlugField()
380
class PrePopulatedSubPost(models.Model):
381
post = models.ForeignKey(PrePopulatedPost)
382
subtitle = models.CharField(max_length=100)
383
subslug = models.SlugField()
386
class Post(models.Model):
387
title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
388
content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
389
posted = models.DateField(
390
default=datetime.date.today,
391
help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
393
public = models.NullBooleanField()
395
def awesomeness_level(self):
396
return "Very awesome."
399
@python_2_unicode_compatible
400
class Gadget(models.Model):
401
name = models.CharField(max_length=100)
407
@python_2_unicode_compatible
408
class Villain(models.Model):
409
name = models.CharField(max_length=100)
415
class SuperVillain(Villain):
419
@python_2_unicode_compatible
420
class FunkyTag(models.Model):
421
"Because we all know there's only one real use case for GFKs."
422
name = models.CharField(max_length=25)
423
content_type = models.ForeignKey(ContentType)
424
object_id = models.PositiveIntegerField()
425
content_object = generic.GenericForeignKey('content_type', 'object_id')
431
@python_2_unicode_compatible
432
class Plot(models.Model):
433
name = models.CharField(max_length=100)
434
team_leader = models.ForeignKey(Villain, related_name='lead_plots')
435
contact = models.ForeignKey(Villain, related_name='contact_plots')
436
tags = generic.GenericRelation(FunkyTag)
442
@python_2_unicode_compatible
443
class PlotDetails(models.Model):
444
details = models.CharField(max_length=100)
445
plot = models.OneToOneField(Plot)
451
@python_2_unicode_compatible
452
class SecretHideout(models.Model):
453
""" Secret! Not registered with the admin! """
454
location = models.CharField(max_length=100)
455
villain = models.ForeignKey(Villain)
461
@python_2_unicode_compatible
462
class SuperSecretHideout(models.Model):
463
""" Secret! Not registered with the admin! """
464
location = models.CharField(max_length=100)
465
supervillain = models.ForeignKey(SuperVillain)
471
@python_2_unicode_compatible
472
class CyclicOne(models.Model):
473
name = models.CharField(max_length=25)
474
two = models.ForeignKey('CyclicTwo')
480
@python_2_unicode_compatible
481
class CyclicTwo(models.Model):
482
name = models.CharField(max_length=25)
483
one = models.ForeignKey(CyclicOne)
489
class Topping(models.Model):
490
name = models.CharField(max_length=20)
493
class Pizza(models.Model):
494
name = models.CharField(max_length=20)
495
toppings = models.ManyToManyField('Topping')
498
class Album(models.Model):
499
owner = models.ForeignKey(User)
500
title = models.CharField(max_length=30)
503
class Employee(Person):
504
code = models.CharField(max_length=20)
507
class WorkHour(models.Model):
508
datum = models.DateField()
509
employee = models.ForeignKey(Employee)
512
class Question(models.Model):
513
question = models.CharField(max_length=20)
516
@python_2_unicode_compatible
517
class Answer(models.Model):
518
question = models.ForeignKey(Question, on_delete=models.PROTECT)
519
answer = models.CharField(max_length=20)
525
class Reservation(models.Model):
526
start_date = models.DateTimeField()
527
price = models.IntegerField()
532
('steve', 'Steve J'),
535
RESTAURANT_CHOICES = (
536
('indian', 'A Taste of India'),
537
('thai', 'Thai Pography'),
538
('pizza', 'Pizza Mama'),
542
class FoodDelivery(models.Model):
543
reference = models.CharField(max_length=100)
544
driver = models.CharField(max_length=100, choices=DRIVER_CHOICES, blank=True)
545
restaurant = models.CharField(max_length=100, choices=RESTAURANT_CHOICES, blank=True)
548
unique_together = (("driver", "restaurant"),)
551
@python_2_unicode_compatible
552
class CoverLetter(models.Model):
553
author = models.CharField(max_length=30)
554
date_written = models.DateField(null=True, blank=True)
560
class Paper(models.Model):
561
title = models.CharField(max_length=30)
562
author = models.CharField(max_length=30, blank=True, null=True)
565
class ShortMessage(models.Model):
566
content = models.CharField(max_length=140)
567
timestamp = models.DateTimeField(null=True, blank=True)
570
@python_2_unicode_compatible
571
class Telegram(models.Model):
572
title = models.CharField(max_length=30)
573
date_sent = models.DateField(null=True, blank=True)
579
class Story(models.Model):
580
title = models.CharField(max_length=100)
581
content = models.TextField()
584
class OtherStory(models.Model):
585
title = models.CharField(max_length=100)
586
content = models.TextField()
589
class ComplexSortedPerson(models.Model):
590
name = models.CharField(max_length=100)
591
age = models.PositiveIntegerField()
592
is_employee = models.NullBooleanField()
594
class PrePopulatedPostLargeSlug(models.Model):
596
Regression test for #15938: a large max_length for the slugfield must not
597
be localized in prepopulated_fields_js.html or it might end up breaking
598
the javascript (ie, using THOUSAND_SEPARATOR ends up with maxLength=1,000)
600
title = models.CharField(max_length=100)
601
published = models.BooleanField()
602
slug = models.SlugField(max_length=1000)
604
class AdminOrderedField(models.Model):
605
order = models.IntegerField()
606
stuff = models.CharField(max_length=200)
608
class AdminOrderedModelMethod(models.Model):
609
order = models.IntegerField()
610
stuff = models.CharField(max_length=200)
611
def some_order(self):
613
some_order.admin_order_field = 'order'
615
class AdminOrderedAdminMethod(models.Model):
616
order = models.IntegerField()
617
stuff = models.CharField(max_length=200)
619
class AdminOrderedCallable(models.Model):
620
order = models.IntegerField()
621
stuff = models.CharField(max_length=200)
623
@python_2_unicode_compatible
624
class Report(models.Model):
625
title = models.CharField(max_length=100)
631
class MainPrepopulated(models.Model):
632
name = models.CharField(max_length=100)
633
pubdate = models.DateField()
634
status = models.CharField(
636
choices=(('option one', 'Option One'),
637
('option two', 'Option Two')))
638
slug1 = models.SlugField()
639
slug2 = models.SlugField()
641
class RelatedPrepopulated(models.Model):
642
parent = models.ForeignKey(MainPrepopulated)
643
name = models.CharField(max_length=75)
644
pubdate = models.DateField()
645
status = models.CharField(
647
choices=(('option one', 'Option One'),
648
('option two', 'Option Two')))
649
slug1 = models.SlugField(max_length=50)
650
slug2 = models.SlugField(max_length=60)
653
class UnorderedObject(models.Model):
655
Model without any defined `Meta.ordering`.
658
name = models.CharField(max_length=255)
659
bool = models.BooleanField(default=True)
661
class UndeletableObject(models.Model):
663
Model whose show_delete in admin change_view has been disabled
666
name = models.CharField(max_length=255)
668
class UserMessenger(models.Model):
670
Dummy class for testing message_user functions on ModelAdmin
673
class Simple(models.Model):
675
Simple model with nothing on it for use in testing
678
class Choice(models.Model):
679
choice = models.IntegerField(blank=True, null=True,
680
choices=((1, 'Yes'), (0, 'No'), (None, 'No opinion')))