PageRenderTime 228ms CodeModel.GetById 120ms app.highlight 9ms RepoModel.GetById 94ms 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
 1"""
 24. Many-to-one relationships
 3
 4To define a many-to-one relationship, use ``ForeignKey()``.
 5"""
 6
 7from django.db import models
 8
 9class Reporter(models.Model):
10    first_name = models.CharField(max_length=30)
11    last_name = models.CharField(max_length=30)
12    email = models.EmailField()
13
14    def __unicode__(self):
15        return u"%s %s" % (self.first_name, self.last_name)
16
17class Article(models.Model):
18    headline = models.CharField(max_length=100)
19    pub_date = models.DateField()
20    reporter = models.ForeignKey(Reporter)
21
22    def __unicode__(self):
23        return self.headline
24
25    class Meta:
26        ordering = ('headline',)