当前位置: 代码迷 >> Web前端 >> 1 Django 1.5.4 入门
  详细解决方案

1 Django 1.5.4 入门

热度:1124   发布时间:2013-10-28 11:21:45.0
一 Django 1.5.4 入门

一.安装

./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