[Django] Creating an app, models and database
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的更多相关文章
- Django~NewProject and APP
New Project 1.新建 django-admin startproject mysite 2.运行 manage.py runserver 8080 New APP 1.manage.py ...
- Django中反向生成models
我们在展示django ORM反向生成之前,我们先说一下怎么样正向生成代码. 正向生成,指的是先创建model.py文件,然后通过django内置的编译器,在数据库如mysql中创建出符合model. ...
- django根据不同app配置相应的log文件
django根据不同app配置相应的log文件 settings.py # django logging LOG_PATH = "/var/log/blog/" LOGGING = ...
- Django 数据库mysql到models的映射方法
Django自动生成models 如果数据库表已经存在,执行命令,可以自动生成Models模型,实现models与数据表的映射 >>> python manage.py inspec ...
- django复习笔记2:models
关于models,主要想说的是django shell以及生成测试数据的脚本这两部分. 一个models中的类相当于数据库的一张表,先看一个设置了外键的models. from django.db i ...
- django 添加comments app
django 添加comments app 参看 django comments 文档 安装和配置comments 1.安装comments,运行:pip install django-contrib ...
- laravel路由无法访问,报404,No query results for model [App\Models\...]
今天遇到了一个问题,在routes/web.php中配置了路由,但始终无法访问该路由,一直报404. Route::resource('gift_packs', 'GiftPacksControlle ...
- 对Yii2中 yii\web\User的理解,和自建的app\models\User(基础版),frontend\models\User的应用原理
yii\web\User 是一个统称,为用户,没有具体实例,只能管理: 此处以app\models\User为基准: app\models\User 是映射数据表user的model类,同时也实现接口 ...
- Django学习笔记009-django models进行数据库增删查改
引入models的定义 from app.models import myclass class myclass(): aa = models. CharField (max_length=No ...
随机推荐
- 2.lombok系列2:lombok注解详解
转自:https://www.imooc.com/article/18157 开篇 看到第一篇<初识lombok>你可能意犹未尽,本文我们按照场景来介绍一下常用的注解. 未特别说明,均标注 ...
- Android代码模拟物理、屏幕点击事件
一.应用中模拟物理和屏幕点击事件 例如,模拟对某个view的点击事件 private void simulateClick(View view, float x, float y) { long do ...
- Oracle 12C R2 on Linux 7.X Data Guard 搭建文档
1.查看主机和数据库信息 [oracle@oracle1 ~]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on ...
- 【Codeforces Round #431 (Div. 2) B】 Tell Your World
[链接]点击打开链接 [题意] n个点,x从左到右严格递增的顺序给出 让你划两条平行的,且没有相同点的直线; 使得它们俩各自最少穿过一个点. 且它们俩穿过了所有的点. [题解] 枚举第一个点和哪个点组 ...
- Windows下编译OpenSSL(使用VS2013)
简述 OpenSSL是一个开源的第三方库,它实现了SSL(Secure SocketLayer)和TLS(Transport Layer Security)协议,被广泛企业应用所采用.对于一般的开发人 ...
- Altium Designer规则的制定,一般规则
资源来源于网上: 1,线间距6~10个mil 2,铺铜间距 20mil 实心 3,焊盘对焊盘间距10mil 4,测量电压的位置要到引脚附近. 敷铜:
- 第一个Python程序(全面)
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 一.Windows系统 1.编写Python程序方式之Sublime文本编辑器: 1>打开sublime,创建hello.p ...
- python3 用递归方法列出所有目录与文件
python3 用递归方法列出所有目录与文件 # !/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import os ...
- Spring Boot 热部署(转)
Spring Boot 热部署 实际开发中,修改某个页面数据或逻辑功能都需要重启应用.这无形中降低了开发效率,所以使用热部署是十分必要的. 什么是热部署? 应用启动后会把编译好的Class文件加载的虚 ...
- 大战C100K之-Linux内核调优篇--转载
原文地址:http://joyexpr.com/2013/11/22/c100k-4-kernel-tuning/ 早期的系统,系统资源包括CPU.内存等都是非常有限的,系统为了保持公平,默认要限制进 ...