1. """
    
  2. Tests for the order_with_respect_to Meta attribute.
    
  3. """
    
  4. 
    
  5. from django.db import models
    
  6. 
    
  7. 
    
  8. class Question(models.Model):
    
  9.     text = models.CharField(max_length=200)
    
  10. 
    
  11. 
    
  12. class Answer(models.Model):
    
  13.     text = models.CharField(max_length=200)
    
  14.     question = models.ForeignKey(Question, models.CASCADE)
    
  15. 
    
  16.     class Meta:
    
  17.         order_with_respect_to = "question"
    
  18. 
    
  19.     def __str__(self):
    
  20.         return self.text
    
  21. 
    
  22. 
    
  23. class Post(models.Model):
    
  24.     title = models.CharField(max_length=200)
    
  25.     parent = models.ForeignKey(
    
  26.         "self", models.SET_NULL, related_name="children", null=True
    
  27.     )
    
  28. 
    
  29.     class Meta:
    
  30.         order_with_respect_to = "parent"
    
  31. 
    
  32.     def __str__(self):
    
  33.         return self.title
    
  34. 
    
  35. 
    
  36. # order_with_respect_to points to a model with a OneToOneField primary key.
    
  37. class Entity(models.Model):
    
  38.     pass
    
  39. 
    
  40. 
    
  41. class Dimension(models.Model):
    
  42.     entity = models.OneToOneField("Entity", primary_key=True, on_delete=models.CASCADE)
    
  43. 
    
  44. 
    
  45. class Component(models.Model):
    
  46.     dimension = models.ForeignKey("Dimension", on_delete=models.CASCADE)
    
  47. 
    
  48.     class Meta:
    
  49.         order_with_respect_to = "dimension"