PageRenderTime 32ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/modeltests/many_to_one_null/models.py

https://code.google.com/p/mango-py/
Python | 24 lines | 12 code | 6 blank | 6 comment | 0 complexity | d2deafd6789a5c2a5ccc283d415b8513 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. 16. Many-to-one relationships that can be null
  3. To define a many-to-one relationship that can have a null foreign key, use
  4. ``ForeignKey()`` with ``null=True`` .
  5. """
  6. from django.db import models
  7. class Reporter(models.Model):
  8. name = models.CharField(max_length=30)
  9. def __unicode__(self):
  10. return self.name
  11. class Article(models.Model):
  12. headline = models.CharField(max_length=100)
  13. reporter = models.ForeignKey(Reporter, null=True)
  14. class Meta:
  15. ordering = ('headline',)
  16. def __unicode__(self):
  17. return self.headline