PageRenderTime 242ms CodeModel.GetById 161ms app.highlight 1ms RepoModel.GetById 79ms 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
 1"""
 216. Many-to-one relationships that can be null
 3
 4To define a many-to-one relationship that can have a null foreign key, use
 5``ForeignKey()`` with ``null=True`` .
 6"""
 7
 8from django.db import models
 9
10class Reporter(models.Model):
11    name = models.CharField(max_length=30)
12
13    def __unicode__(self):
14        return self.name
15
16class Article(models.Model):
17    headline = models.CharField(max_length=100)
18    reporter = models.ForeignKey(Reporter, null=True)
19
20    class Meta:
21        ordering = ('headline',)
22
23    def __unicode__(self):
24        return self.headline