PageRenderTime 28ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modeltests/many_to_one/models.py

https://code.google.com/p/mango-py/
Python | 26 lines | 15 code | 6 blank | 5 comment | 0 complexity | 609b59f60113462deb3a1e12ad858202 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. 4. Many-to-one relationships
  3. To define a many-to-one relationship, use ``ForeignKey()``.
  4. """
  5. from django.db import models
  6. class Reporter(models.Model):
  7. first_name = models.CharField(max_length=30)
  8. last_name = models.CharField(max_length=30)
  9. email = models.EmailField()
  10. def __unicode__(self):
  11. return u"%s %s" % (self.first_name, self.last_name)
  12. class Article(models.Model):
  13. headline = models.CharField(max_length=100)
  14. pub_date = models.DateField()
  15. reporter = models.ForeignKey(Reporter)
  16. def __unicode__(self):
  17. return self.headline
  18. class Meta:
  19. ordering = ('headline',)