To add a new app, first cd to the project.

Then run:

python manage.py startapp scrumboard

After that a new folder call 'scrumboard' will be created in you applicaiton folder.

Now cd to scrumboard folder and open models.py:

from django.db import models
from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible
class List(models.Model):
name = models.CharField(max_length=50) def __str__(self):
return "List {}".format(self.name) @python_2_unicode_compatible
class Card(models.Model):
title = models.CharField(max_length=100)
description = models.TextField(blank=True) def __str__(self):
return "Card {}".format(self.title)

Add a database:

python manage.py makemigrations

It check whether there is anything changed in my models.py file.

And you can see there is a new file generated inside 'migrations folder' called 0001_initial.py.

Now let's do migrations:

python manage.py migrate

If we did any changes in models.py, we need to run mirgration again:

from django.db import models
from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible
class List(models.Model):
name = models.CharField(max_length=50) def __str__(self):
return "List {}".format(self.name) @python_2_unicode_compatible
class Card(models.Model):
title = models.CharField(max_length=100)
description = models.TextField(blank=True)
list = models.ForeignKey(List, related_name="cards")
story_points = models.IntegerField(null=True, blank=True)
business_value = models.IntegerField(null=True, blank=True) def __str__(self):
return "Card {}".format(self.title)

More docs for Model: https://docs.djangoproject.com/en/1.9/topics/db/models/

[Django] Creating an app, models and database的更多相关文章

  1. Django~NewProject and APP

    New Project 1.新建 django-admin startproject mysite 2.运行 manage.py runserver 8080 New APP 1.manage.py ...

  2. Django中反向生成models

    我们在展示django ORM反向生成之前,我们先说一下怎么样正向生成代码. 正向生成,指的是先创建model.py文件,然后通过django内置的编译器,在数据库如mysql中创建出符合model. ...

  3. django根据不同app配置相应的log文件

    django根据不同app配置相应的log文件 settings.py # django logging LOG_PATH = "/var/log/blog/" LOGGING = ...

  4. Django 数据库mysql到models的映射方法

    Django自动生成models 如果数据库表已经存在,执行命令,可以自动生成Models模型,实现models与数据表的映射 >>> python manage.py inspec ...

  5. django复习笔记2:models

    关于models,主要想说的是django shell以及生成测试数据的脚本这两部分. 一个models中的类相当于数据库的一张表,先看一个设置了外键的models. from django.db i ...

  6. django 添加comments app

    django 添加comments app 参看 django comments 文档 安装和配置comments 1.安装comments,运行:pip install django-contrib ...

  7. laravel路由无法访问,报404,No query results for model [App\Models\...]

    今天遇到了一个问题,在routes/web.php中配置了路由,但始终无法访问该路由,一直报404. Route::resource('gift_packs', 'GiftPacksControlle ...

  8. 对Yii2中 yii\web\User的理解,和自建的app\models\User(基础版),frontend\models\User的应用原理

    yii\web\User 是一个统称,为用户,没有具体实例,只能管理: 此处以app\models\User为基准: app\models\User 是映射数据表user的model类,同时也实现接口 ...

  9. Django学习笔记009-django models进行数据库增删查改

    引入models的定义 from app.models import  myclass class  myclass(): aa =  models. CharField (max_length=No ...

随机推荐

  1. CSU1660: K-Cycle

    Description A simple cycle is a closed simple path, with no other repeated vertices or edges other t ...

  2. mmx-编译脚本

    脚本目录位置 /home/zhangshuli/git2/vanzo_team/xulei/Mmx.py 在-/bin目录下,链接Mmx.py ln -sf ~/git2/vanzo_team/xul ...

  3. 1.1 Introduction中 Topics and Logs官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Topics and Logs 话题和日志 (Topic和Log) Let's fi ...

  4. 1.13 Python基础知识 - 字典和集合

    一.字典 字典是一组键-值对的数据结构.每个键对应一个值.在字典中,键不能重复.根据键可以查询到值.字典是键和值的映射关系 字典的定义: 字典通过花括号中用逗号分隔的元素(键-值.键-值对使用冒号分隔 ...

  5. 洛谷 P2969 [USACO09DEC]音符Music Notes

    P2969 [USACO09DEC]音符Music Notes 题目描述 FJ is going to teach his cows how to play a song. The song cons ...

  6. Java核心技术 卷Ⅰ 基础知识(4)

    第六章 接口与内部类 接口 特性 接口与抽象类 对象克隆 接口与回调 内部类 使用内部类访问对象状态 内部类的特殊语法规则 局部内部类 匿名内部类 静态内部类 代理 Class[] in=new Cl ...

  7. ds1302模块的一个arduino程序

    /* * 读写DS1302 时钟芯片 * @author Yangtf * 很棒的文档 http://www.21ic.com/jichuzhishi/datasheet/DS1302/data/18 ...

  8. Javascript和jquery事件--鼠标滚轮事件WheelEvent

    <1>js事件 滚轮事件在js中,不同浏览器还是有不同的,介于我只测试谷歌和火狐浏览器的情况,其他浏览器有待自行探索.有三种写法: target.onmousewheel = wheel; ...

  9. 格式化时间的一个好方法(补充moment)

    /** * * 格式化时间 * @param {*} time * @param {*} fmt * @returns * time(new Date(), 'yyyy/MM/dd') ==> ...

  10. 最新GitHub账号注册(详细图解)

    说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 一.简介 GitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. ...