1. """
    
  2. Bare-bones model
    
  3. 
    
  4. This is a basic model with only two non-primary-key fields.
    
  5. """
    
  6. import uuid
    
  7. 
    
  8. from django.db import models
    
  9. 
    
  10. 
    
  11. class Article(models.Model):
    
  12.     headline = models.CharField(max_length=100, default="Default headline")
    
  13.     pub_date = models.DateTimeField()
    
  14. 
    
  15.     class Meta:
    
  16.         ordering = ("pub_date", "headline")
    
  17. 
    
  18.     def __str__(self):
    
  19.         return self.headline
    
  20. 
    
  21. 
    
  22. class FeaturedArticle(models.Model):
    
  23.     article = models.OneToOneField(Article, models.CASCADE, related_name="featured")
    
  24. 
    
  25. 
    
  26. class ArticleSelectOnSave(Article):
    
  27.     class Meta:
    
  28.         proxy = True
    
  29.         select_on_save = True
    
  30. 
    
  31. 
    
  32. class SelfRef(models.Model):
    
  33.     selfref = models.ForeignKey(
    
  34.         "self",
    
  35.         models.SET_NULL,
    
  36.         null=True,
    
  37.         blank=True,
    
  38.         related_name="+",
    
  39.     )
    
  40.     article = models.ForeignKey(Article, models.SET_NULL, null=True, blank=True)
    
  41. 
    
  42.     def __str__(self):
    
  43.         # This method intentionally doesn't work for all cases - part
    
  44.         # of the test for ticket #20278
    
  45.         return SelfRef.objects.get(selfref=self).pk
    
  46. 
    
  47. 
    
  48. class PrimaryKeyWithDefault(models.Model):
    
  49.     uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
    
  50. 
    
  51. 
    
  52. class ChildPrimaryKeyWithDefault(PrimaryKeyWithDefault):
    
  53.     pass