Django學習筆記(二)
六、創建模型
python manage.py startapp polls
polls/
__init__.py
admin.py
migrations/
__init__.py
models.py
tests.py
views.py
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
no action 表示不做任何操作,
set null 表示在外鍵表中將相應字段設置爲null
set default 表示設置爲默認值
cascade 表示級聯操作
python manage.py createsuperuser
時區設置