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特征点提取类进行修改,对图像进行分块提取,而后划分节点,使得每个节点中保存的特征点性能是该节点所有特征点中最好的. ...
随机推荐
- vue state
vuex单一状态树,直接地定位任一特定的状态片段. vuex状态存储响应式,唯一store实例,从store中读取状态: 1.在计算属性中返回某个状态 2.在根实例中注册store选项,该 store ...
- [IOS][已越狱]配合网易云音乐,使用Bridge快速免iTunes导入音乐到“音乐”
前置:已越狱IOS设备 工具表: Bridge{bigboss源,可以使用cydown以非官方服务器下载安装} 网易云音乐{Appstore} Filza{很多源都有} 网易云试听缓存路径 ...
- req和resp常用的方法
req: 1. setAttribute()在Request域中存储数据 2. setCharacterEncoding()设置请求参数的编码方式,只对post请求有效 3. getMethod() ...
- Android项目——触摸按键控制LED
一.Android Studio应用编程 1.应用程序界面layout对应的界面是activity_main.xml,后台对应的java文件是MainActivity.java,修改activity_ ...
- layer.open弹出窗口后在子页面修改弹窗的title
在子页面修改layer.open弹窗的title,代码如下: var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索 ...
- MySQL 设置root密码报错:mysqladmin: connect to server at 'localhost' failed
MySQL 设置root密码报错:mysqladmin: connect to server at 'localhost' failed 1.安装完MySQL设置root密码报错如下 [root@vm ...
- 开始转变方向,学习Linux——《Linux就该这么学》
三十而立,四十不惑. 我呢,未立将不惑. 苦恼之余,决定拓展就业范围,正式学习Linux,准备考取RHCE证书. 考证需要报名培训机构,这是一个明智的选择,毕竟中国人善于考试,善于钻研考试. 联系培训 ...
- JS将/Date(1446704778000)/转换成str
JS将/Date(1446704778000)/转换成str:var dateStr = eval(ele.add_time.replace(/\/Date\((\d+)\)\//gi, " ...
- 黄聪:C#中CefSharp的简单使用
C#中CefSharp的简单使用 https://blog.csdn.net/qq_26712977/article/details/78282995
- webRTC中音频相关的netEQ(四):控制命令决策
上篇(webRTC中音频相关的netEQ(三):存取包和延时计算)讲了语音包的存取以及网络延时和抖动缓冲延时的计算,MCU也收到了DSP模块发来的反馈报告.本文讲MCU模块如何根据网络延时.抖动缓冲延 ...