models.py 977 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. """
  3. Bare-bones model
  4. This is a basic model with only two non-primary-key fields.
  5. """
  6. from django.db import models
  7. from django.utils.encoding import python_2_unicode_compatible
  8. @python_2_unicode_compatible
  9. class Article(models.Model):
  10. headline = models.CharField(max_length=100, default='Default headline')
  11. pub_date = models.DateTimeField()
  12. class Meta:
  13. ordering = ('pub_date', 'headline')
  14. def __str__(self):
  15. return self.headline
  16. class ArticleSelectOnSave(Article):
  17. class Meta:
  18. proxy = True
  19. select_on_save = True
  20. @python_2_unicode_compatible
  21. class SelfRef(models.Model):
  22. selfref = models.ForeignKey(
  23. 'self',
  24. models.SET_NULL,
  25. null=True, blank=True,
  26. related_name='+',
  27. )
  28. def __str__(self):
  29. # This method intentionally doesn't work for all cases - part
  30. # of the test for ticket #20278
  31. return SelfRef.objects.get(selfref=self).pk