models.py 940 B

12345678910111213141516171819202122232425262728293031
  1. """
  2. Tests for built in Function expressions.
  3. """
  4. from __future__ import unicode_literals
  5. from django.db import models
  6. from django.utils.encoding import python_2_unicode_compatible
  7. @python_2_unicode_compatible
  8. class Author(models.Model):
  9. name = models.CharField(max_length=50)
  10. alias = models.CharField(max_length=50, null=True, blank=True)
  11. goes_by = models.CharField(max_length=50, null=True, blank=True)
  12. def __str__(self):
  13. return self.name
  14. @python_2_unicode_compatible
  15. class Article(models.Model):
  16. authors = models.ManyToManyField(Author, related_name='articles')
  17. title = models.CharField(max_length=50)
  18. summary = models.CharField(max_length=200, null=True, blank=True)
  19. text = models.TextField()
  20. written = models.DateTimeField()
  21. published = models.DateTimeField(null=True, blank=True)
  22. views = models.PositiveIntegerField(default=0)
  23. def __str__(self):
  24. return self.title