models.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import unicode_literals
  2. from django.db import models
  3. from django.utils.encoding import python_2_unicode_compatible
  4. @python_2_unicode_compatible
  5. class Reporter(models.Model):
  6. first_name = models.CharField(max_length=30)
  7. last_name = models.CharField(max_length=30)
  8. email = models.EmailField()
  9. facebook_user_id = models.BigIntegerField(null=True)
  10. raw_data = models.BinaryField(null=True)
  11. small_int = models.SmallIntegerField()
  12. class Meta:
  13. unique_together = ('first_name', 'last_name')
  14. def __str__(self):
  15. return "%s %s" % (self.first_name, self.last_name)
  16. @python_2_unicode_compatible
  17. class Article(models.Model):
  18. headline = models.CharField(max_length=100)
  19. pub_date = models.DateField()
  20. body = models.TextField(default='')
  21. reporter = models.ForeignKey(Reporter, models.CASCADE)
  22. response_to = models.ForeignKey('self', models.SET_NULL, null=True)
  23. def __str__(self):
  24. return self.headline
  25. class Meta:
  26. ordering = ('headline',)
  27. index_together = [
  28. ["headline", "pub_date"],
  29. ]