~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/modeltests/many_to_one_null/models.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
16. Many-to-one relationships that can be null
3
 
 
4
 
To define a many-to-one relationship that can have a null foreign key, use
5
 
``ForeignKey()`` with ``null=True`` .
6
 
"""
7
 
 
8
 
from django.db import models
9
 
from django.utils.encoding import python_2_unicode_compatible
10
 
 
11
 
 
12
 
@python_2_unicode_compatible
13
 
class Reporter(models.Model):
14
 
    name = models.CharField(max_length=30)
15
 
 
16
 
    def __str__(self):
17
 
        return self.name
18
 
 
19
 
@python_2_unicode_compatible
20
 
class Article(models.Model):
21
 
    headline = models.CharField(max_length=100)
22
 
    reporter = models.ForeignKey(Reporter, null=True)
23
 
 
24
 
    class Meta:
25
 
        ordering = ('headline',)
26
 
 
27
 
    def __str__(self):
28
 
        return self.headline