| 1 |
from django.apps.registry import Apps |
| 2 |
from django.db import models |
| 3 |
|
| 4 |
# Because we want to test creation and deletion of these as separate things, |
| 5 |
# these models are all inserted into a separate Apps so the main test |
| 6 |
# runner doesn't migrate them. |
| 7 |
|
| 8 |
new_apps = Apps() |
| 9 |
|
| 10 |
|
| 11 |
class Author(models.Model): |
| 12 |
name = models.CharField(max_length=255) |
| 13 |
height = models.PositiveIntegerField(null=True, blank=True) |
| 14 |
weight = models.IntegerField(null=True, blank=True) |
| 15 |
uuid = models.UUIDField(null=True) |
| 16 |
|
| 17 |
class Meta: |
| 18 |
apps = new_apps |
| 19 |
|
| 20 |
|
| 21 |
class AuthorCharFieldWithIndex(models.Model): |
| 22 |
char_field = models.CharField(max_length=31, db_index=True) |
| 23 |
|
| 24 |
class Meta: |
| 25 |
apps = new_apps |
| 26 |
|
| 27 |
|
| 28 |
class AuthorTextFieldWithIndex(models.Model): |
| 29 |
text_field = models.TextField(db_index=True) |
| 30 |
|
| 31 |
class Meta: |
| 32 |
apps = new_apps |
| 33 |
|
| 34 |
|
| 35 |
class AuthorWithDefaultHeight(models.Model): |
| 36 |
name = models.CharField(max_length=255) |
| 37 |
height = models.PositiveIntegerField(null=True, blank=True, default=42) |
| 38 |
|
| 39 |
class Meta: |
| 40 |
apps = new_apps |
| 41 |
|
| 42 |
|
| 43 |
class AuthorWithEvenLongerName(models.Model): |
| 44 |
name = models.CharField(max_length=255) |
| 45 |
height = models.PositiveIntegerField(null=True, blank=True) |
| 46 |
|
| 47 |
class Meta: |
| 48 |
apps = new_apps |
| 49 |
|
| 50 |
|
| 51 |
class AuthorWithIndexedName(models.Model): |
| 52 |
name = models.CharField(max_length=255, db_index=True) |
| 53 |
|
| 54 |
class Meta: |
| 55 |
apps = new_apps |
| 56 |
|
| 57 |
|
| 58 |
class AuthorWithUniqueName(models.Model): |
| 59 |
name = models.CharField(max_length=255, unique=True) |
| 60 |
|
| 61 |
class Meta: |
| 62 |
apps = new_apps |
| 63 |
|
| 64 |
|
| 65 |
class AuthorWithUniqueNameAndBirthday(models.Model): |
| 66 |
name = models.CharField(max_length=255) |
| 67 |
birthday = models.DateField() |
| 68 |
|
| 69 |
class Meta: |
| 70 |
apps = new_apps |
| 71 |
unique_together = [["name", "birthday"]] |
| 72 |
|
| 73 |
|
| 74 |
class Book(models.Model): |
| 75 |
author = models.ForeignKey(Author, models.CASCADE) |
| 76 |
title = models.CharField(max_length=100, db_index=True) |
| 77 |
pub_date = models.DateTimeField() |
| 78 |
# tags = models.ManyToManyField("Tag", related_name="books") |
| 79 |
|
| 80 |
class Meta: |
| 81 |
apps = new_apps |
| 82 |
|
| 83 |
|
| 84 |
class BookWeak(models.Model): |
| 85 |
author = models.ForeignKey(Author, models.CASCADE, db_constraint=False) |
| 86 |
title = models.CharField(max_length=100, db_index=True) |
| 87 |
pub_date = models.DateTimeField() |
| 88 |
|
| 89 |
class Meta: |
| 90 |
apps = new_apps |
| 91 |
|
| 92 |
|
| 93 |
class BookWithLongName(models.Model): |
| 94 |
author_foreign_key_with_really_long_field_name = models.ForeignKey( |
| 95 |
AuthorWithEvenLongerName, |
| 96 |
models.CASCADE, |
| 97 |
) |
| 98 |
|
| 99 |
class Meta: |
| 100 |
apps = new_apps |
| 101 |
|
| 102 |
|
| 103 |
class BookWithO2O(models.Model): |
| 104 |
author = models.OneToOneField(Author, models.CASCADE) |
| 105 |
title = models.CharField(max_length=100, db_index=True) |
| 106 |
pub_date = models.DateTimeField() |
| 107 |
|
| 108 |
class Meta: |
| 109 |
apps = new_apps |
| 110 |
db_table = "schema_book" |
| 111 |
|
| 112 |
|
| 113 |
class BookWithSlug(models.Model): |
| 114 |
author = models.ForeignKey(Author, models.CASCADE) |
| 115 |
title = models.CharField(max_length=100, db_index=True) |
| 116 |
pub_date = models.DateTimeField() |
| 117 |
slug = models.CharField(max_length=20, unique=True) |
| 118 |
|
| 119 |
class Meta: |
| 120 |
apps = new_apps |
| 121 |
db_table = "schema_book" |
| 122 |
|
| 123 |
|
| 124 |
class BookWithoutAuthor(models.Model): |
| 125 |
title = models.CharField(max_length=100, db_index=True) |
| 126 |
pub_date = models.DateTimeField() |
| 127 |
|
| 128 |
class Meta: |
| 129 |
apps = new_apps |
| 130 |
db_table = "schema_book" |
| 131 |
|
| 132 |
|
| 133 |
class BookForeignObj(models.Model): |
| 134 |
title = models.CharField(max_length=100, db_index=True) |
| 135 |
author_id = models.IntegerField() |
| 136 |
|
| 137 |
class Meta: |
| 138 |
apps = new_apps |
| 139 |
|
| 140 |
|
| 141 |
class IntegerPK(models.Model): |
| 142 |
i = models.IntegerField(primary_key=True) |
| 143 |
j = models.IntegerField(unique=True) |
| 144 |
|
| 145 |
class Meta: |
| 146 |
apps = new_apps |
| 147 |
db_table = "INTEGERPK" # uppercase to ensure proper quoting |
| 148 |
|
| 149 |
|
| 150 |
class Note(models.Model): |
| 151 |
info = models.TextField() |
| 152 |
address = models.TextField(null=True) |
| 153 |
|
| 154 |
class Meta: |
| 155 |
apps = new_apps |
| 156 |
|
| 157 |
|
| 158 |
class NoteRename(models.Model): |
| 159 |
detail_info = models.TextField() |
| 160 |
|
| 161 |
class Meta: |
| 162 |
apps = new_apps |
| 163 |
db_table = "schema_note" |
| 164 |
|
| 165 |
|
| 166 |
class Tag(models.Model): |
| 167 |
title = models.CharField(max_length=255) |
| 168 |
slug = models.SlugField(unique=True) |
| 169 |
|
| 170 |
class Meta: |
| 171 |
apps = new_apps |
| 172 |
|
| 173 |
|
| 174 |
class TagM2MTest(models.Model): |
| 175 |
title = models.CharField(max_length=255) |
| 176 |
slug = models.SlugField(unique=True) |
| 177 |
|
| 178 |
class Meta: |
| 179 |
apps = new_apps |
| 180 |
|
| 181 |
|
| 182 |
class TagUniqueRename(models.Model): |
| 183 |
title = models.CharField(max_length=255) |
| 184 |
slug2 = models.SlugField(unique=True) |
| 185 |
|
| 186 |
class Meta: |
| 187 |
apps = new_apps |
| 188 |
db_table = "schema_tag" |
| 189 |
|
| 190 |
|
| 191 |
# Based on tests/reserved_names/models.py |
| 192 |
class Thing(models.Model): |
| 193 |
when = models.CharField(max_length=1, primary_key=True) |
| 194 |
|
| 195 |
class Meta: |
| 196 |
apps = new_apps |
| 197 |
db_table = "drop" |
| 198 |
|
| 199 |
def __str__(self): |
| 200 |
return self.when |
| 201 |
|
| 202 |
|
| 203 |
class UniqueTest(models.Model): |
| 204 |
year = models.IntegerField() |
| 205 |
slug = models.SlugField(unique=False) |
| 206 |
|
| 207 |
class Meta: |
| 208 |
apps = new_apps |
| 209 |
unique_together = ["year", "slug"] |
| 210 |
|
| 211 |
|
| 212 |
class Node(models.Model): |
| 213 |
node_id = models.AutoField(primary_key=True) |
| 214 |
parent = models.ForeignKey("self", models.CASCADE, null=True, blank=True) |
| 215 |
|
| 216 |
class Meta: |
| 217 |
apps = new_apps |