django之关联field 描述子
"""
Accessors for related objects.
When a field defines a relation between two models, each model class provides
an attribute to access related instances of the other model class (unless the
reverse accessor has been disabled with related_name='+').
Accessors are implemented as descriptors in order to customize access and
assignment. This module defines the descriptor classes.
Forward accessors follow foreign keys. Reverse accessors trace them back. For
example, with the following models::
class Parent(Model):
pass
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
``child.parent`` is a forward many-to-one relation. ``parent.children`` is a
reverse many-to-one relation.
There are three types of relations (many-to-one, one-to-one, and many-to-many)
and two directions (forward and reverse) for a total of six combinations.
1. Related instance on the forward side of a many-to-one or one-to-one
relation: ``ForwardManyToOneDescriptor``.
Uniqueness of foreign key values is irrelevant to accessing the related
instance, making the many-to-one and one-to-one cases identical as far as
the descriptor is concerned. The constraint is checked upstream (unicity
validation in forms) or downstream (unique indexes in the database).
If you're looking for ``ForwardOneToOneDescriptor``, use
``ForwardManyToOneDescriptor`` instead.
2. Related instance on the reverse side of a one-to-one relation:
``ReverseOneToOneDescriptor``.
One-to-one relations are asymmetrical, despite the apparent symmetry of the
name, because they're implemented in the database with a foreign key from
one table to another. As a consequence ``ReverseOneToOneDescriptor`` is
slightly different from ``ForwardManyToOneDescriptor``.
3. Related objects manager for related instances on the reverse side of a
many-to-one relation: ``ReverseManyToOneDescriptor``.
Unlike the previous two classes, this one provides access to a collection
of objects. It returns a manager rather than an instance.
4. Related objects manager for related instances on the forward or reverse
sides of a many-to-many relation: ``ManyToManyDescriptor``.
Many-to-many relations are symmetrical. The syntax of Django models
requires declaring them on one side but that's an implementation detail.
They could be declared on the other side without any change in behavior.
Therefore the forward and reverse descriptors can be the same.
If you're looking for ``ForwardManyToManyDescriptor`` or
``ReverseManyToManyDescriptor``, use ``ManyToManyDescriptor`` instead.
"""
django之关联field 描述子的更多相关文章
- django之关联field 描述子是如何实现的
model定义时,每个field都是一个类属性,一个对象.在生成类时,属性有contribute_to_class的方法,会调用该方法. m2m field,它会先调用自己的contribute_to ...
- django之relacted.py(探秘django的关联field)
生成model类对象时,传入的每个field对象都会调用其contribute_to_class函数,生成对应的属性. def contribute_to_class(self, cls, name, ...
- django自关联,auth模块
一.自关联 写蛮好的一篇博客:https://www.cnblogs.com/Kingfan1993/p/9936541.html 1.一对多关联 1.表内自关联是指表内数据相关联的对象和表是相同字段 ...
- BRIEF 特征描述子
Binary Robust Independent Elementary Features www.cnblogs.com/ronny 1. BRIEF的基本原理 我们已经知道SIFT特征采用了128 ...
- 基于HOG-3D的时空描述子
作者提出一种新的基于局部描述子的行为识别算法.
- Brief描述子
一.Brief算法 1.基本原理 BRIEF是2010年的一篇名为<BRIEF:Binary Robust Independent Elementary Features>的文章中提出,B ...
- SIFT算法:特征描述子
SIFT算法:DoG尺度空间生产 SIFT算法:KeyPoint找寻.定位与优化 SIFT算法:确定特征点方向 SIFT算法:特征描述子 目录: 1.确定描述子采样区域 2.生成描述子 2.1 旋 ...
- SIFT解析(三)生成特征描述子
以上两篇文章中检测在DOG空间中稳定的特征点,lowe已经提到这些特征点是比Harris角点等特征还要稳定的特征.下一步骤我们要考虑的就是如何去很好地描述这些DOG特征点. 下面好好说说如何来描述这些 ...
- (二)ORB描述子提取源码思路与实现
ORBSLAM2中ORB特征提取的特点 ORBSLAM2中通过对OpenCV中的ORB特征点提取类进行修改,对图像进行分块提取,而后划分节点,使得每个节点中保存的特征点性能是该节点所有特征点中最好的. ...
随机推荐
- 入学java的第一天
登录http://www.oracle.com,下载JDK(J2SE) JDK 1.0,1.1,1.2,1.3,1.4 1.5(JDK5.0) 支持注解.支持泛型 1.6(JDK6.0)Server2 ...
- webpack学习笔记(四)
1 webpack的垫片 举个例子,在main文件中引入jquery和doash两个库: import $ from 'jquery'; import _ from 'lodash'; import ...
- slb
第一章 弹性负载均衡slb概要介绍 第一讲什么是弹性负载均衡slb 互联网应用的服务扩展 负载均衡诞生 slb的引出 slb产品介绍 负载均衡 server load balancer 是对多台云 ...
- VMware Workstation Pro 安装win7系统
1.准备工作VMware Workstation Pro 虚拟机软件cn_windows_7_enterprise_x64_dvd_x15-70741.iso2.选择典型(推荐)(T) 单选按钮 3. ...
- 使用 Flask-Docs 自动生成 Api 文档
影响我写文档的原因可能是代码和文档分离,有时候写完代码会忘记补文档,而且不能及时查看,使用 Flask-Docs 可以解决我的问题,这个插件可以根据代码注释生成文档页面,代码注释改动文档可以及时更新, ...
- js通過name获取input框输入值
var account = $("input[name='account']").val();//获取input框输入值
- 【代码问题】MatConvNet自带example中 fast_rcnn_evaluate出错
fast_rcnn_evaluate中调用cnn_setup_data_voc07函数读取相关数据时,在类似 [gtids,t]=textread(sprintf(VOCopts.imgsetpath ...
- <ROS> message_filters 对齐多种传感器数据的时间戳
联合标定三维雷达和IMU,第一步要先对齐两种传感信息的时间戳. ros官网提供了message_filters用于对齐多种传感信息的时间戳. http://wiki.ros.org/message_f ...
- Kong配置参考
kong配置的官网说明:https://docs.konghq.com/1.0.x/configuration/ 1. 配置加载 如果您通过其中一个官方软件包安装了Kong,Kong会附带默认配置文件 ...
- 总结:Java 集合进阶精讲2-ArrayList
知识点:Java 集合框架图 总结:Java 集合进阶精讲1 总结:Java 集合进阶精讲2-ArrayList 初探: ArrayList底层结构是数组,是List接口的 可变数组的实现,所以会占用 ...