一.安装
./manage.py startapp beer
二.修改beer/models.py
一个Brewery生厂多种beer,一个beer只对应一个Brewery
from django.db import models # Create your models here. BEER_CHOICES=( ('D','Domestic'), ('I','Import'), ) class Beer(models.Model): name =models.CharField(max_length=200) slug =models.SlugField(unique=True) brewery =models.ForeignKey('Brewery') locality =models.CharField(max_length=1,choices=BEER_CHOICES) description =models.TextField(blank=True) def __unicode__(self): return self.name class Brewery(models.Model): name =models.CharField(max_length=200) slug =models.SlugField(unique=True) description =models.TextField(blank=True) def __unicode__(self): return self.name
在settings.py中INSTALLED_APPS添加beer
./manage.py syncdb