【Django 018】Django2.2数据模型models的继承以及abstract的使用

从平衡车到机器人:聊聊STM32自平衡小车项目里那些能复用的核心技能 本文深入探讨了STM32自平衡小车项目的核心技术,包括姿态感知、PID控制、电机驱动等关键技能,并展示了这些技术如何迁移到机器人开发中。通过实战案例和代码示例,帮助开发者掌握嵌入式系统设计的精髓,提升项目复用能力。 阅读详情

python做为一门面向对象语音,其继承特性是做的非常好的。如果能在models定义中将一些通用字段放在父类中,子类直接继承,然后添加一些自己独有的字段,岂不是可以省很多创建模型的时间。这一篇我们就来看看这个问题。

我是T型人小付,一位坚持终身学习的互联网从业者。喜欢我的博客欢迎在csdn上关注我,如果有问题欢迎在底下的评论区交流,谢谢。

纯语法定义继承

在models.py中创建如下People类做为一会要用的父类

class People(models.Model):
    p_name = models.CharField(max_length=16)
    p_sex = models.BooleanField(default=True)

然后创建两个子类American和Chinese继承自People

class American(People):
    a_state = models.CharField(max_length=16)


class Chinese(People):
    c_province = models.CharField(max_length=16)

按照正常逻辑,我们只想要American和Chinese这两张表,但是完成makemigrations和migrate以后和我们设想的不一样,一共出现了三张表,也就是说People表也被创建了。

而且在American和Chinese中都多了一个叫people_ptr_id的字段,查看DDL如下

create table Four_american
(
    people_ptr_id int         not null
        primary key,
    a_state       varchar(16) not null,
    constraint Four_american_people_ptr_id_733979de_fk_Four_people_id
        foreign key (people_ptr_id) references Four_people (id)
);
create table Four_chinese
(
    people_ptr_id int         not null
        primary key,
    c_province    varchar(16) not null,
    constraint Four_chinese_people_ptr_id_15a467cd_fk_Four_people_id
        foreign key (people_ptr_id) references Four_people (id)
);

发现这个people_ptr_id既是每个表的主键,又是指向父类表主键的一个外键。按照前面的学习,这是一对一的SQL逻辑。下面我们就往两个子类的表中添加数据来验证一下。

创建如下的路由和view函数来添加数据

path('add_american/', views.add_american, name='add_american'),
path('add_chinese/', views.add_chinese, name='add_chinese'),
def add_american(request):
    state = request.GET.get('state')
    name = request.GET.get('name')
    american = American()
    american.p_name = name
    american.a_state = state
    american.save()
    return HttpResponse('Add american successfully')


def add_chinese(request):
    province = request.GET.get('province')
    name = request.GET.get('name')
    chinese = Chinese()
    chinese.p_name = name
    chinese.c_province = province
    chinese.save()
    return HttpResponse('Add chinese successfully')

然后就可以通过类似http://127.0.0.1:8000/four/add_chinese/?province=hubei&name=hanmeimei和http://127.0.0.1:8000/four/add_american/?state=californiai&name=james来添加数据了。结果生成的数据如下

American:
1-american.png

Chinese:
2-chinese.png

People:
3-people.png

添加的数据在添加到American或者Chinese的同时也会被添加到People中,并且通过id或者people_ptr_id来唯一确定。

这显然不是我们想要的现象,理想的情况是子类只继承父类的字段,而每个子类是彼此独立的。

直接执行python manage.py migrate Four 0003_auto_20200401_2321撤销这一次的迁移

关于迁移的原理和撤销回退操作可以参考我的另一篇博客《Django2.2中迁移(makemigrations和migrate)的原理和撤销回退操作图文详解》

加上Abstract定义继承

撤销了上面的迁移以后,我们修改下models.py中的People的定义

class People(models.Model):
    p_name = models.CharField(max_length=16)
    p_sex = models.BooleanField(default=True)

    class Meta:
        abstract = True

这里在Meta中添加了abstract=True的说明,将People变为一个抽象类,也就意味着不会在数据库中显示了。

然后再进行迁移,之后发现数据库中只有子类的两个表了
4-abstract.png

点开两个表看一下,发现成功继承了People的p_name和p_sex字段

American:
5-new-american.png

Chinese:
6-new-chinese.png

这表结构和我们之前设想的一样,DDL也证明没有和别的表关联

create table Four_chinese
(
    id         int auto_increment
        primary key,
    p_name     varchar(16) not null,
    p_sex      tinyint(1)  not null,
    c_province varchar(16) not null
);
create table Four_american
(
    id      int auto_increment
        primary key,
    p_name  varchar(16) not null,
    p_sex   tinyint(1)  not null,
    a_state varchar(16) not null
);

下面来添加数据验证下,同样使用上面的路由和view函数,通过类似http://127.0.0.1:8000/four/add_american/?state=maryland&name=james和http://127.0.0.1:8000/four/add_chinese/?province=taiwan&name=amei来添加数据。

发现两个表的数据是完全独立的,id彼此没有顺序

American:
7-american.png

Chinese:
8-chinese.png

这样就达到了只继承字段,不添加额外表关联的目的。

总结

企业开发中,合理利用继承可以使得模型的创建更高效。不过还有另一种情况,就是和你合作的那个数据开发不会写python所以只能写好SQL,给了你一堆现成的表,又该如何反向转为Django中的模型供我们使用呢?我们下一篇一起来看看这个问题。

FPGA之全数字锁相环(DPLL) 1. 数字锁相环的基本原理和组成 1.1 锁相环(PLL)的简介 锁相环最开始并不是用在数字电路中,而是模拟短路中。对于模拟电路中的锁相环,大家可以参考这篇文章稍微看一下,数字和模拟只是实现的方法不同,但是原理、步骤还是共同的。关于模拟PLL。可以参考一片文章: http://www.sohu.com/a/190569594_464086 首先在学习数字锁相环之前,我们应该先了解什么是锁相环?锁相... 阅读详情

相关推荐

【OpenBMC 系列】4.启动流程 使用qume模拟ast2600-evb

1.安装openbmc适配的qume 2.启动bmc 3.使用bmc web

AiFool的博客 4473

【Django】Django ORM详细使用方法

一个布尔类型的变量,如果设置为True,则标识当前的Model是抽象基类,这个元选项不具有传递性,只对当前声明的类有效。由于每一个数据表对应一个Model定义,每一个Model都是一个Python类,所以,Model之间是可以继承的。设置了choices的字段在管理后台的显示上会由文本框变成选择框,选择框中的可选值就是choices中的元组。Meta类用于定义Model的元数据,即不属于Model的字段,但是可以用来标识它的一些属性。的子类,Django会根据Field的类型确定数据库表的字段类型。

大河之犬的博客 1194

Field II 超声相控阵仿真系列:多角度平面波相干合成提升成像质量

本文深入探讨了Field II超声相控阵仿真中,如何通过多角度平面波相干合成技术提升成像质量。针对单次平面波成像对比度与分辨率不足的问题,详细解析了从探头建模、多角度发射延时计算到回波数据相干合成的完整流程,并提供了关键参数调优建议,以实现图像质量与计算效率的平衡。

weixin_29284885的博客 264

Django model 中meta options之 abstract

Django model 中meta options之 abstract 当abstract=True时,这个model就变成了abstrct base class,那这个基类有什么特性呢? 当某一model中设置了abstract=True时,就会使该model中的字段都不会产生对应的表,而是可以作为基类加入到其他model中 那有什么用...

weixin_30312557的博客 239

2.实体机安装TrueNAS 方法

访问不了可以使用以下连接:提取码:0927。

Unofficial_user的博客 7469

C语言实验——各位数字之和排序

C语言实验——各位数字之和排序Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description给定n个正整数,根据各位数字之和从小到大进行排序。 Input输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面...

aiLMengi000的博客 1251

初识Django(七):Model(模型)总述

注:以下的属性/函数列表都是选的一些常用的,还有其他属性/函数,请另外查找资料。 模型(Model)简介 Django中的模型类可以看做对数据库中的表的另一种显示方法。与直接创建并操作数据库不同,django提供了另外一种更简单的方式在后端对数据进行操作,也就是:django提供了一系列函数让你在直接操作数据,而不需要关注数据库方面的内容,这种方法被称为对象关系映射(Object Relational Mapping,ORM)。(但是我们还需要注意的是,django的model并没有它介绍的这么精密,有

AugustTheodor的博客 2794

手把手教你用STM32CubeMX配置I3C通信(含动态地址分配实战)

本文提供了一份基于STM32CubeMX配置I3C通信的实战指南,重点讲解了动态地址分配的实现步骤。通过详细的工程配置、从设备枚举、CCC命令使用及数据读写示例,帮助开发者快速掌握这一高效通信协议,以替代传统的I2C或SPI接口,满足多传感器连接与低功耗设计需求。

c8d9e0f1的博客 561

Django中model中的抽象类

是一个标识,标识当前类只用于为其他类提供公共的字段(继承关系),并不会单独创建一张表。但是我们也可以对其默认配置修改,定义model类但是不在数据库中创建。后,Django就会在数据库中创建表。文件中定义model表并执行。这张表中,除了有自己定义的。字段,还有继承过来的。

m0_72839702的博客 555

Claude Code 学习笔记之一:理解 Agentic Loop 与内置工具

本文介绍了Claude Code这一终端智能助手的工作原理与使用方式。作者从ABAP开发经验出发,指出学习Claude Code的高级用法具有长期价值。文章详细解析了Claude Code的Agentic Loop机制:通过大语言模型进行推理,借助各类工具执行任务,并循环收集上下文、执行操作、验证结果三个步骤。系统阐述了Claude Code支持的五大类工具及其扩展方式,说明了其访问本地资源的范围和自治处理能力,同时介绍了权限模式等安全机制。最后提供了从小任务开始、充分探索、及时引导、使用CLAUDE.md

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 573

116、影像质量主观评价方法论:标准场景与专家判读

本文探讨了影像质量主观评价的方法论,强调标准场景构建和专家判读体系的重要性。作者基于15年行业经验指出,仅靠客观指标无法保证观感质量,提出四类标准场景(灰阶、肤色、纹理、动态)的构建原则和四种专家判读维度(通透性、干净度、自然感、流程化)。文章揭示了主观评价中的常见误区,包括光源单一性、个人判读偏差、显示设备影响等,并建议建立多专家交叉验证机制和主观评价数据库。最后强调主观评价是可标准化的专业技术,需要将人眼感知转化为可追溯的技术参数。

sundong_81的博客 45

Django系列教程(5)——Django模型详解

假设你要开发一个名叫bookstore的应用,专门来管理书店里的书籍。我们首先要为书本和出版社创建模型。出版社有名字和地址。书有名字,描述和添加日期。我们还需要利用ForeignKey定义了出版社与书本之间单对多的关系,因为一个出版社可以出版很多书,每本书都有对应的出版社。我们定义了Publisher和Book模型,它们都继承了。你能看出代码有什么问题吗?模型创建好后,当你运行CharField里的max_length选项没有定义里的on_delete选项有没有定义。

彩蛋在每篇文章的最后名片 2025

uniapp [安卓苹果App端] - 实现集成微信一键登录及授权获取用户信息全流程源码,uniApp唤起微信客户端app实现微信授权头像昵称手机号(提供移动应用/开放平台/资质认证/签名/权限申请

uni-app,安卓Android,苹果ios,安卓app端,苹果App端,uniapp苹果安卓app,微信一键登录,uniapp项目App端实现微信登录,Uniapp实现微信授权登录,调起微信客户端授权用户信息,uniappapp端微信一键登录打开手机微信app,app端如何唤起用户本机微信应用并授权登陆,如何申请微信一键登录,uniapp实现APP微信登录流程,打开本地微信软件,接入微信登录,UniApp实现微信登录教程,获取头像昵称手机号用户数据,超详细实现微信登录功能,唤起没反应,授权失败,获取

🏆 前端领域优质创作者 1万+

Django模型的继承

Django模型的继承,包括模型的抽象基类、Meta继承、related_name和related_query_name属性、多表继承、Meta和多表继承、继承与反向关系、代理模型、代理模型继承和未托管模型,以及多重继承等内容。子类UserInfo因为继承自基类CommonInfo,所以顺带继承了基类CommonInfo中的name和age属性,这样子类UserInfo就拥有了3个字段属性,即name、age和home_group。在Django模型中,抽象基类在将公共信息放入很多模型时会非常有用。

夏天又到了的专栏 1447

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

django model meta类定义abstract = True

class TimeStampedModel(models.Model): """ An abstract base class model that provides selfupdating ``created`` and ``modified`` fields. """ created = models.DateTimeField(auto_now_add=True) modif

zhangweigangweiwu的专栏 6417

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

django模型中的抽象类(abstract)

首先介绍下django的模型有哪些属性:先看例子: Django 模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性。以下对此作一总结: abstract 这个属性是定义当前的模型类是不是一个抽象类。所谓抽象类是不会对应数据库表的。一般我们用它来归纳一些公共属性字段,然后继承它的子类可以继承这些字段。比如下面的代码中Human是一个抽象类,Employee是一...

weixin_30390075的博客 751

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

odoo 基类 models.AbstractModel 基本操作

在Odoo中,创建一个AbstractModel通常涉及到继承models.AbstractModel类,并定义模型的方法。在Odoo中,AbstractModel是一个特殊的模型类型,用于创建无需存储在数据库中的模型,它通常用作其他模型的基础,对其进行扩展和复用方法。在上述代码中,_name是定义模型标识的必要参数,而_description是可选参数,用于提供模型的简单描述。创建服务型模型,它们为其他模型提供服务,例如,进行计算或管理配置数据,但本身不直接关联数据库表。继承AbstractModel。

StackSurfer的博客 716

Django之Model的Meta选项详解

Django默认生成的表名: 应用名小写_模型类名小写 可以通过在模型类中定义Meta类来修改表名: class Department(models.Model): """部门类""" name = models.CharField(max_length=20) create_date = models.DateField(auto_now_add=True) ...

菲宇运维 1万+

django的model继承abstract,proxy,managed

https://www.cnblogs.com/wangwei916797941/p/9525127.html?from=timeline 转载于:https://www.cnblogs.com/1a2a/p/11208663.html

weixin_30305735的博客 221

django1.8 model (1):Model syntax

此文翻译自django 1.8.2官方文档Models模型是单一的,明确的和你的数据有关的信息的来源.它包含了你存储的数据的基本字段和行为.通常,一个模型对应一个数据库表. 基础知识: - 每个模型都是django.db.model.Model的子类 - 模型的每个属性都代表一个数据库字段 - 在这2个前提下,django提供了自动生成(automatically-generated)数据库

黑猫警长的博客 1568

Django_Model详解

Models model是对于信息的一种模型封装与定义。它包含了你要存储的必要字段和操作数据的方法。一句话概括就是,每个模型映射了一张数据表。 基本概念: 每个model都是继承于django.db.models.Model 的Python类。 model的每一个属性对应数据表中的一个字段。 通过所有的这些,Django提供了一个自动化生成访问数据库的API。 简单实例 这个例子...

XL的博客 3361

Django Meta内部类选项

转自:[url]http://www.onepub.net/2012/02/02/django-meta%E5%86%85%E9%83%A8%E7%B1%BB%E9%80%89%E9%A1%B9/[/url] Django 模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性。以下对此作一总结: abstract 这个属性是定义当前的模型类是不是一个抽象...

greybeard的专栏 569

odoo10(12)自定义视图

实现效果类似企业版会计报表的效果 首先补充一下odoo中对象的几种类型 基础模型BaseModel,以下几种类型依次继承 1、models.AbstractModel 抽象模型,不会在数据库中创建对应表 2、models.Model 安装或升级会自动在数据库中创建对应表 3、models.TransientModel 临时表,在数据库中有对应表,但是数据会定期清理 根据这三种类似,在自定义视图时选...

l732893879的博客 1460

Django中的Model继承

Django 中的 model 继承和 Python 中的类继承非常相似,只不过你要选择具体的实现方式:让父 model 拥有独立的数据库;还是让父 model 只包含基本的公共信息,而这些信息只能由子 model 呈现。 Django中有三种继承关系: 1.通常,你只是想用父 model 来保存那些你不想在子 model 中重复录入的信息。父类是不使用的也就是不生成单独的数据表,这种情况下使...

weixin_33752045的博客 359

【odoo】odoo中的三种模型

odoo中的三种模型

Hello, World!!! 776

Odoo二次开发------Odoo常用字段类型

版权声明:本文由神州数码云基地团队整理撰写,若转载请注明出处。 大家好。本篇文章主要讲述的内容是Odoo常用字段类型。 本文将从Odoo模型概述、Odoo的常规字段、自动字段和保留字段、常用字段属性、四个小节进行分享 1、Odoo模型概述 1.1 初识Model odoo中的Model分为三类 models.AbstractModel 抽象模块: 类似于抽象类,常用于继承 models.Model 基础模块: 会根据字段和模型名在后台数据库生成对应的数据表文件常用此类Model .

在数字化道路无限探索 2104
上一篇: Django2.2中迁移(makemigrations和migrate)的原理和撤销回退操作图文详解
下一篇: 【Django 019】SQL表转变为Django中的models图文详解
T型人小付
博客等级 码龄7年 433粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址