Models

A model is the single, definitive source of information about your data. It contains the essential fields and behaviors of the data you're storing. Generally, each model maps to a single database table.

The basics:

  • Each model is a Python class that subclasses django.db.models.Model.
  • Each attribute of the model represents a database field.
  • With all of this, Django gives you an automatically-generated database-access API; see Making queries.

    Quick example

    Using models

    Fields

    Field types

    Field options

    null

    blank

    choices

    default

    help_text

    primary_key

    unique

    Automatic primary key fields

    Verbose field names

    Relationships

    Many-to-one relationships

    Many-to-many relationships

    Extra fields on many-to-many relationships

    One-to-one relationships

    Models across files

    Field name restrictions

    Custom field types

    Meta options

    Model methods

    Overriding predefined model methods

    Overriding predefined model methods

    Executing custom SQL

    Model inheritance

    Abstract base classes

    Meta inheritance

    Be careful with related_name

    Multi-table inheritance

    Meta and multi-table inheritance

    Proxy models

    Base class restrictions

    Multiple inheritance

    Field name "hiding" is not permitted

#module-django.db.models的更多相关文章

  1. Python 报错 AttributeError: module 'django.db.models' has no attribute 'SubfieldBase'

    AttributeError: module 'django.db.models' has no attribute 'SubfieldBase' http://www.guanggua.com/qu ...

  2. django - from django.db.models import F - class F

    F() 的执行不经过 python解释器,不经过本机内存,是生成 SQL语句的执行. # Tintin filed a news story! reporter = Reporters.objects ...

  3. Django | Unable to get repr for <class 'django.db.models.query.QuerySet'>

    问题:在mysql中查询数据时,代码如下: skus = category.sku_set.filter(is_launched=True).order_by(sort_field) skus 取不到 ...

  4. django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist: Course has no coursedetail.

    错误描述: 一对一反向查询失败! 前提: Course和CourseDetail    OneToOne 原因: Course数据和CourseDetail数据没有一一对应.

  5. django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist

    Enrollment has no customer.

  6. 【Django】--Models 和ORM以及admin配置

    Models 数据库的配置 1    django默认支持sqlite,mysql, oracle,postgresql数据库 <1>sqlite django默认使用sqlite的数据库 ...

  7. django.db.utils.DataError: (1406, "Data too long for column 'gender' at row 1")

    报错现象 在使用 django 创建 超级用户的时候提示报错 Password (again): ytyt521521 Traceback (most recent call last): File ...

  8. Django 之 models的 F() 和 Q() 函数

    前提: app名称为core,models.py 如下: #coding: utf8 import datetime from django.db import models class Order( ...

  9. 【Python】django模型models的外键关联使用

    Python 2.7.10,django 1.8.6 外键关联:http://www.bubuko.com/infodetail-618303.html 字段属性:http://www.cnblogs ...

随机推荐

  1. C/C++基础(二)

    (1)运算符优先级 #include <cstdio> using namespace std; int main() {    unsigned char a = 0xA5;    un ...

  2. firefox如何restart重启

    1.开发者工具栏可以对firefox进行重启,不是关闭firefox又打开那种重启

  3. SQL profile纵览(10g)

    第一篇:介绍         10g开始,查询优化器(Query optimizer)扩展成自动调整优化器(Automatic Tuning Optimizer).也就是扩展了功能.此时,我们就可以让 ...

  4. iOS开发总结-图片左右滑动浏览

    // // PicViewController.m // BJ // // Created by shirenfeng on 16/9/13. // Copyright © 2016年 com.zyb ...

  5. Windows 服务卸载之后 重新安装提示 “指定的服务已标记为删除”

    背景:        将一个项目做成一个windows服务,在调试的时候,需要卸载.安装该服务,但提示下面的错误:“指定的服务已标记为删除”,进入服务管理界面,启动自己注册的服务,无法手动更改成启用模 ...

  6. java几种字符串反转

    java实现的字符串翻转,能想到的这几种方法 假设有其它方法,欢迎交流 //字符串反转 public class ReverseString { public String reverse1(Stri ...

  7. Qt 学习之路 :使用 QJson 处理 JSON

    XML 曾经是各种应用的配置和传输的首选方式.但是现在 XML 遇到了一个强劲的对手:JSON.我们可以在 这里 看到有关 JSON 的语法.总体来说,JSON 的数据比 XML 更紧凑,在传输效率上 ...

  8. 利用Java API通过路径过滤上传多文件至HDFS

    在本地文件上传至HDFS过程中,很多情况下一个目录包含很多个文件,而我们需要对这些文件进行筛选,选出符合我们要求的文件,上传至HDFS.这时就需要我们用到文件模式. 在项目开始前,我们先掌握文件模式 ...

  9. 解读dbcp自动重连那些事---转载

    http://agapple.iteye.com/blog/791943 可以后另一篇做对比:http://agapple.iteye.com/blog/772507 同样的内容,不同的描述方式,不一 ...

  10. [转] Mac OX上安装MongoDb

    https://scotch.io/tutorials/an-introduction-to-mongodb MongoDB的安装有好多种安装方法,有普通青年的HomeBrew方式,也有文艺青年的源码 ...