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. mysql登录时,ERROR 1045 (28000): 错误解决办法

    错误问题的描述: ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO) ERROR 10 ...

  2. python_Opencv_opencv2.4.4+python配置问题

    下载numpy-1.8.1-win32-superpack-python2.7.exe.下载地址微博微盘:http://vdisk.weibo.com/s/aJcp4pI6mYEXg 必须安装nump ...

  3. 【转】eclipse插件:OpenExplorer快速打开文件目录

    在MyEclipse开发中常用到其中一个"Open In Explorer"的小插件,可以直接进入Windows资源管理器中打开选中文件所在的目录,在使用eclipse开发时也很需 ...

  4. (一)Windows下搭建PHP开发环境及相关注意事项

    PHP集成开发环境有很多,如XAMPP.AppServ......只要一键安装就把PHP环境给搭建好了.但这种安装方式不够灵活,软件的自由组合不方便,同时也不利于学习.所以我还是喜欢手工搭建PHP开发 ...

  5. 关于谷歌、火狐 右键没有发送到onenote选项

                              关于chrome .FF 右键没有发送到onenote选项 问题: 使用Microsoft  office中的onenote作为自己平时学习和工作的 ...

  6. dom4j的基本操作

    /** * 建立一个XML文档,文档名由输入属性决定 * @param filename 需建立的文件名 * @return 返回操作结果, 0表失败, 1表成功 */ import java.io. ...

  7. OpenRisc-42-or1200的ALU模块分析

    引言 computer(计算机),顾名思义,就是用来compute(计算)的.计算机体系结构在上世纪五六十年代的时候,主要就是研究如何设计运算部件,就是想办法用最少的元器件(那时元器件很贵),最快的速 ...

  8. JQuery ajax调用asp.net的webMethod

    本文章转载:http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html 在vs2010中,用JQuery ajax调用as ...

  9. [RxJS] Filtering operators: throttle and throttleTime

    Debounce is known to be a rate-limiting operator, but it's not the only one. This lessons introduces ...

  10. android 16 带返回值的activity

    main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" andro ...