mirror of
https://github.com/django/django.git
synced 2024-12-25 02:26:12 +00:00
d02ba7f4ee
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17450 bcc190cf-cafb-0310-a4f2-bffc1f526a37
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""
|
|
7. The lookup API
|
|
|
|
This demonstrates features of the database API.
|
|
"""
|
|
|
|
from django.db import models
|
|
|
|
|
|
class Author(models.Model):
|
|
name = models.CharField(max_length=100)
|
|
class Meta:
|
|
ordering = ('name', )
|
|
|
|
class Article(models.Model):
|
|
headline = models.CharField(max_length=100)
|
|
pub_date = models.DateTimeField()
|
|
author = models.ForeignKey(Author, blank=True, null=True)
|
|
class Meta:
|
|
ordering = ('-pub_date', 'headline')
|
|
|
|
def __unicode__(self):
|
|
return self.headline
|
|
|
|
class Tag(models.Model):
|
|
articles = models.ManyToManyField(Article)
|
|
name = models.CharField(max_length=100)
|
|
class Meta:
|
|
ordering = ('name', )
|
|
|
|
class Season(models.Model):
|
|
year = models.PositiveSmallIntegerField()
|
|
gt = models.IntegerField(null=True, blank=True)
|
|
|
|
def __unicode__(self):
|
|
return unicode(self.year)
|
|
|
|
class Game(models.Model):
|
|
season = models.ForeignKey(Season, related_name='games')
|
|
home = models.CharField(max_length=100)
|
|
away = models.CharField(max_length=100)
|
|
|
|
def __unicode__(self):
|
|
return u"%s at %s" % (self.away, self.home)
|
|
|
|
class Player(models.Model):
|
|
name = models.CharField(max_length=100)
|
|
games = models.ManyToManyField(Game, related_name='players')
|
|
|
|
def __unicode__(self):
|
|
return self.name |