2
16. Many-to-one relationships that can be null
4
To define a many-to-one relationship that can have a null foreign key, use
5
``ForeignKey()`` with ``null=True`` .
8
from django.db import models
9
from django.utils.encoding import python_2_unicode_compatible
12
@python_2_unicode_compatible
13
class Reporter(models.Model):
14
name = models.CharField(max_length=30)
19
@python_2_unicode_compatible
20
class Article(models.Model):
21
headline = models.CharField(max_length=100)
22
reporter = models.ForeignKey(Reporter, null=True)
25
ordering = ('headline',)