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 AuthorWithIndexedNameAndBirthday(models.Model):
    
  66.     name = models.CharField(max_length=255)
    
  67.     birthday = models.DateField()
    
  68. 
    
  69.     class Meta:
    
  70.         apps = new_apps
    
  71.         index_together = [["name", "birthday"]]
    
  72. 
    
  73. 
    
  74. class AuthorWithUniqueNameAndBirthday(models.Model):
    
  75.     name = models.CharField(max_length=255)
    
  76.     birthday = models.DateField()
    
  77. 
    
  78.     class Meta:
    
  79.         apps = new_apps
    
  80.         unique_together = [["name", "birthday"]]
    
  81. 
    
  82. 
    
  83. class Book(models.Model):
    
  84.     author = models.ForeignKey(Author, models.CASCADE)
    
  85.     title = models.CharField(max_length=100, db_index=True)
    
  86.     pub_date = models.DateTimeField()
    
  87.     # tags = models.ManyToManyField("Tag", related_name="books")
    
  88. 
    
  89.     class Meta:
    
  90.         apps = new_apps
    
  91. 
    
  92. 
    
  93. class BookWeak(models.Model):
    
  94.     author = models.ForeignKey(Author, models.CASCADE, db_constraint=False)
    
  95.     title = models.CharField(max_length=100, db_index=True)
    
  96.     pub_date = models.DateTimeField()
    
  97. 
    
  98.     class Meta:
    
  99.         apps = new_apps
    
  100. 
    
  101. 
    
  102. class BookWithLongName(models.Model):
    
  103.     author_foreign_key_with_really_long_field_name = models.ForeignKey(
    
  104.         AuthorWithEvenLongerName,
    
  105.         models.CASCADE,
    
  106.     )
    
  107. 
    
  108.     class Meta:
    
  109.         apps = new_apps
    
  110. 
    
  111. 
    
  112. class BookWithO2O(models.Model):
    
  113.     author = models.OneToOneField(Author, models.CASCADE)
    
  114.     title = models.CharField(max_length=100, db_index=True)
    
  115.     pub_date = models.DateTimeField()
    
  116. 
    
  117.     class Meta:
    
  118.         apps = new_apps
    
  119.         db_table = "schema_book"
    
  120. 
    
  121. 
    
  122. class BookWithSlug(models.Model):
    
  123.     author = models.ForeignKey(Author, models.CASCADE)
    
  124.     title = models.CharField(max_length=100, db_index=True)
    
  125.     pub_date = models.DateTimeField()
    
  126.     slug = models.CharField(max_length=20, unique=True)
    
  127. 
    
  128.     class Meta:
    
  129.         apps = new_apps
    
  130.         db_table = "schema_book"
    
  131. 
    
  132. 
    
  133. class BookWithoutAuthor(models.Model):
    
  134.     title = models.CharField(max_length=100, db_index=True)
    
  135.     pub_date = models.DateTimeField()
    
  136. 
    
  137.     class Meta:
    
  138.         apps = new_apps
    
  139.         db_table = "schema_book"
    
  140. 
    
  141. 
    
  142. class BookForeignObj(models.Model):
    
  143.     title = models.CharField(max_length=100, db_index=True)
    
  144.     author_id = models.IntegerField()
    
  145. 
    
  146.     class Meta:
    
  147.         apps = new_apps
    
  148. 
    
  149. 
    
  150. class IntegerPK(models.Model):
    
  151.     i = models.IntegerField(primary_key=True)
    
  152.     j = models.IntegerField(unique=True)
    
  153. 
    
  154.     class Meta:
    
  155.         apps = new_apps
    
  156.         db_table = "INTEGERPK"  # uppercase to ensure proper quoting
    
  157. 
    
  158. 
    
  159. class Note(models.Model):
    
  160.     info = models.TextField()
    
  161.     address = models.TextField(null=True)
    
  162. 
    
  163.     class Meta:
    
  164.         apps = new_apps
    
  165. 
    
  166. 
    
  167. class NoteRename(models.Model):
    
  168.     detail_info = models.TextField()
    
  169. 
    
  170.     class Meta:
    
  171.         apps = new_apps
    
  172.         db_table = "schema_note"
    
  173. 
    
  174. 
    
  175. class Tag(models.Model):
    
  176.     title = models.CharField(max_length=255)
    
  177.     slug = models.SlugField(unique=True)
    
  178. 
    
  179.     class Meta:
    
  180.         apps = new_apps
    
  181. 
    
  182. 
    
  183. class TagIndexed(models.Model):
    
  184.     title = models.CharField(max_length=255)
    
  185.     slug = models.SlugField(unique=True)
    
  186. 
    
  187.     class Meta:
    
  188.         apps = new_apps
    
  189.         index_together = [["slug", "title"]]
    
  190. 
    
  191. 
    
  192. class TagM2MTest(models.Model):
    
  193.     title = models.CharField(max_length=255)
    
  194.     slug = models.SlugField(unique=True)
    
  195. 
    
  196.     class Meta:
    
  197.         apps = new_apps
    
  198. 
    
  199. 
    
  200. class TagUniqueRename(models.Model):
    
  201.     title = models.CharField(max_length=255)
    
  202.     slug2 = models.SlugField(unique=True)
    
  203. 
    
  204.     class Meta:
    
  205.         apps = new_apps
    
  206.         db_table = "schema_tag"
    
  207. 
    
  208. 
    
  209. # Based on tests/reserved_names/models.py
    
  210. class Thing(models.Model):
    
  211.     when = models.CharField(max_length=1, primary_key=True)
    
  212. 
    
  213.     class Meta:
    
  214.         apps = new_apps
    
  215.         db_table = "drop"
    
  216. 
    
  217.     def __str__(self):
    
  218.         return self.when
    
  219. 
    
  220. 
    
  221. class UniqueTest(models.Model):
    
  222.     year = models.IntegerField()
    
  223.     slug = models.SlugField(unique=False)
    
  224. 
    
  225.     class Meta:
    
  226.         apps = new_apps
    
  227.         unique_together = ["year", "slug"]
    
  228. 
    
  229. 
    
  230. class Node(models.Model):
    
  231.     node_id = models.AutoField(primary_key=True)
    
  232.     parent = models.ForeignKey("self", models.CASCADE, null=True, blank=True)
    
  233. 
    
  234.     class Meta:
    
  235.         apps = new_apps