Django Admin后台添加数据库视图过程解析
作者:临渊 时间:2024-01-27 06:40:17
你通过以下语句,创建了一个数据库视图:
create view entities_entity as
select id, name from entities_hero
union
select 10000+id as id, name from entities_villain
它包含所有Hero和Villain对象的名称。Villain对象的的ID被设置都加上10000,因为Hero对象的数量不会超过这个数字。
sqlite> select * from entities_entity;
1|Krishna
2|Vishnu
3|Achilles
4|Thor
5|Zeus
6|Athena
7|Apollo
10001|Ravana
10002|Fenrir
然后添加一个managed=False模型:
class AllEntity(models.Model):
name = models.CharField(max_length=100)
class Meta:
managed = False
db_table = "entities_entity"
并将其添加到Admin后台:
@admin.register(AllEntity)
class AllEntiryAdmin(admin.ModelAdmin):
list_display = ("id", "name")
效果如下。
来源:https://www.cnblogs.com/superhin/p/12192485.html
标签:Django,Admin,后台,数据库,视图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解基于Node.js的微信JS-SDK后端接口实现代码
2024-05-02 17:37:47
![](https://img.aspxhome.com/file/2023/6/129486_0s.png)
python 数据库查询返回list或tuple实例
2024-01-25 01:28:45
Python切片操作实例分析
2022-05-02 17:49:25
Python实现内存泄露排查的示例详解
2021-03-03 21:55:29
以图换字的几个方法及思路
2007-10-17 18:07:00
Bootstrap实现圆角、圆形头像和响应式图片
2023-08-12 07:16:59
![](https://img.aspxhome.com/file/2023/2/56052_0s.jpg)
sqlserver实现oracle的sequence方法
2024-01-21 01:53:47
CentOS7.4手动安装MySQL5.7的方法
2024-01-28 01:12:20
python 删除非空文件夹的实例
2022-11-07 01:25:23
你是真正的用户体验设计者吗? Ⅵ
2008-04-19 18:23:00
![](https://img.aspxhome.com/file/UploadPic/20084/19/200841918321625s.jpg)
python中 logging的使用详解
2023-01-11 21:31:14
一个基于flask的web应用诞生 bootstrap框架美化(3)
2023-12-04 02:30:39
![](https://img.aspxhome.com/file/2023/8/86488_0s.png)
Python判断文件或文件夹是否存在的三种方法
2021-04-25 21:53:06
pandas 实现将两列中的较大值组成新的一列
2022-12-24 04:50:01
PyHacker编写URL批量采集器
2022-03-21 12:42:21
![](https://img.aspxhome.com/file/2023/5/67345_0s.png)
新手学python应该下哪个版本
2021-09-06 00:04:45
Python中缓存lru_cache的基本介绍和讲解
2021-09-30 08:23:08
python错误提示:Errno 2] No such file or directory的解决方法
2022-03-30 10:46:26
![](https://img.aspxhome.com/file/2023/2/115862_0s.png)
asp如何显示最后十名来访者信息?
2010-06-09 18:45:00
python-xpath获取html文档的部分内容
2022-10-06 19:41:52
![](https://img.aspxhome.com/file/2023/1/131191_0s.jpg)