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特征点提取类进行修改,对图像进行分块提取,而后划分节点,使得每个节点中保存的特征点性能是该节点所有特征点中最好的. ...
随机推荐
- BOM模型中常用对象 定义计数器 网页跳转 网页前进后退
今天上午学了的BOM模型中常用对象,了解了一部分的属性 For循环的规律 外层循环控制行 内层循环控制列 <!doctype html> <html> <head> ...
- 剖析servlet injection及源码分析.
@WebServlet("/cdiservlet") public class NewServlet extends HttpServlet { private Message m ...
- 使用python读取MS-SQL数据库
使用python读取MS-SQL中的数据,这里使用到模板pymssql. 因为不是python自带的模板,所以首先需要使用pip安装,对应命令:pip install pymssql 建立main.p ...
- InsertSort
#include <bits/stdc++.h> using namespace std; #define MAXSIZE 200000 typedef int KeyType; type ...
- ANSYS稳态热分析
目录 题目 APDL操作 温度云图 题目 管子内径外径为r1=4.125mm,r2=4.635mm,中间物体的产热功率为Q=8.73e8W/m3,管外有温度t=127℃的冷水流过,冷却水与管子外表面的 ...
- Servlet接口UML图
Servlet.class源码
- Hbase各版本环境要求
1.HBase各版本JDK支持情况 HBase Version JDK 7 JDK 8 JDK 9 JDK 10 2.0 Not Supported yes Not Support ...
- HttpWebResponse Post 前端控件数据,后台如何接收?
MVC视图页: @{ Layout = null; } <!DOCTYPE html> <html> <head> <title>test</ti ...
- ecmobile-页面空白,也没异常提示,一般就是这个问题
分类页空白了://2018年09月07日14:55:21 四:页面空白 将ON_WILL_APPEAR中有关页面布局方法写在ON_DID_APPEAR方法中.例如:
- fcn训练及预测tgs数据集
一.背景 kaggle上有这样一个题目,关于盐份预测的语义分割题目.TGS Salt Identification Challenge | Kaggle https://www.kaggle.com ...