django 笔记

2018-04-03  本文已影响1人  42chaos

model.py

from django.db import models


class Quesstion(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    question = models.ForeignKey(Quesstion,on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

setting.py加入config

INSTALLED_APPS = [
    'polls.apps.PollsConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

创建数据库表结构

$ python3 manage.py makemigrations polls

django的shell

python3 manage.py shell
上一篇下一篇

猜你喜欢

热点阅读