/tests/modeltests/order_with_respect_to/models.py

https://code.google.com/p/mango-py/ · Python · 29 lines · 17 code · 9 blank · 3 comment · 0 complexity · 5ff40a4729a1dd570954bf3133c4c69f MD5 · raw file

  1. """
  2. Tests for the order_with_respect_to Meta attribute.
  3. """
  4. from django.db import models
  5. class Question(models.Model):
  6. text = models.CharField(max_length=200)
  7. class Answer(models.Model):
  8. text = models.CharField(max_length=200)
  9. question = models.ForeignKey(Question)
  10. class Meta:
  11. order_with_respect_to = 'question'
  12. def __unicode__(self):
  13. return unicode(self.text)
  14. class Post(models.Model):
  15. title = models.CharField(max_length=200)
  16. parent = models.ForeignKey("self", related_name="children", null=True)
  17. class Meta:
  18. order_with_respect_to = "parent"
  19. def __unicode__(self):
  20. return self.title