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. OrmLite使用小结(一)

    在使用OrmLite过程中,遇到了不少问题.鉴于中文文档比較少,看英文文档又不知道怎样看起.仅仅能遇到问题查找解决方法并整理出来,如有错误,希望能指正! ** 1.模糊条件查询 ** 使用条件查询时. ...

  2. 地图上显示div点位

    功能核心:  地理坐标转屏幕坐标 用到的插件:jquery  animo动画插件 核心代码: var point = new Point(lon, lat, map.spatialReference) ...

  3. shell-查看手机分辨率

    使用如下命令,可以查看手机分辨率 adb shell dumpsys window displays 运行结果如下 Display: mDisplayId= init=1080x1920 480dpi ...

  4. 使用solr的DIHandler 构建mysql大表全量索引,内存溢出问题的解决方法

    solr官方给出的解决方式是: DataImportHandler is designed to stream row one-by-one. It passes a fetch size value ...

  5. C# socket beginAccept

    服务端:    需要增加的命名空间:using System.Threading;using System.Net;using System.Net.Sockets;    以下是具体实现.C# co ...

  6. asp.net--TextBox属性全研究

    . .aspx代码例如以下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="T ...

  7. hadoop组件及其作用

    1.hadoop有三个主要的核心组件:HDFS(分布式文件存储).MAPREDUCE(分布式的计算).YARN(资源调度),现在云计算包括大数据和虚拟化进行支撑. 在HADOOP(hdfs.MAPRE ...

  8. Exsi SSH 服务配置

    vi /etc/ssh/sshd_conf禁止口令验证PasswordAuthentication no禁止root登录PermitRootLogin no ESXi Shell F2--F2--Tr ...

  9. 读文件头数据判断 PE 文件格式和类型

    namespace X.Reflection { using System; using System.IO; public static partial class ReflectionX { pu ...

  10. element ui源码解析 -- input篇

    el-input是element ui中使用最频繁的组件之一了,分析其构成从四个方面入手:DOM结构,属性,样式,事件入手 DOM结构: <div> <input /> < ...