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. 来看看Github上流行的编码规范

      Popular Coding Convention on Github是一个有趣的网站,它根据Github的代码提交情况分析了几种语言流行的代码规范,目前支持对JavaScript,Java,Py ...

  2. LCA在线算法ST算法

    求LCA(近期公共祖先)的算法有好多,按在线和离线分为在线算法和离线算法. 离线算法有基于搜索的Tarjan算法较优,而在线算法则是基于dp的ST算法较优. 首先说一下ST算法. 这个算法是基于RMQ ...

  3. (转载)Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记

    Linux下安装配置MySQL+Apache+PHP+WordPress的详细笔记 Linux下配LMAP环境,花了我好几天的时间.之前没有配置过,网上的安装资料比较混乱,加上我用的版本问题,安装过程 ...

  4. 移动web设计稿尺寸,关于移动web尺寸的那点事

    我自己的做稿子的时候,一开始就有一个习惯,先放上这段代码<meta name="viewport" content="width=device-width, ini ...

  5. angular应用前景

    完成了angularJs的学习,突然想到,angularJS是否会影响到seo.于是查阅了很多资料,技术博客,这种想法得到了证实. 爬虫不能识别js渲染的内容.所以引起了我对angular应用前景的思 ...

  6. Asp.net主题(theme)和皮肤(skin)的使用

    asp.net 的服务器端控件提供了多种样式的设计,如果对每个控件都单独设置,是比较繁琐的事情,所以微软也提供了针对这些服务器端控件的样式管理,其实也可以通过 css来控制部分服务器端控件的样式,比如 ...

  7. 我是一块cpu 《转载》

    我是一块cpu,原装intel,在一台普通的台式计算机里供职.我有个小弟是内存,我要靠他时时刻刻陪伴我工作,其实有时候我并不是没有某某地址的资料,而是懒得翻--麻烦. 还有一个老大哥叫bios,每次那 ...

  8. 彻底删除mysql的方法(有隐藏文件)

    1.建议使用360进行卸载,可以彻底卸载软件 2.360会提醒删除注册表 3.这个隐藏文件要删除掉 在 C:\Documents and Settings\ 路径下搜索 MySQL 文件夹(默认隐藏的 ...

  9. poj1828

    poj1828 [问题的描述]是这样的:程序猿的近亲 猴子(......)最近在进行王位争夺站. 题中使用二维坐标轴上的点(x,y)来代表猴子所占有的位置, 每只猴子占有一个坐标点.并且一个坐标点上面 ...

  10. java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??

    严重: Error starting endpoint java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???? ...