#module-django.db.models

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

上一篇:转:VIM选择文本块/复制/粘贴


下一篇:二进制流 最后一段数据是最后一次读取的byte数组没填满造成的