python – Django:如何在list_display中包含内联模型字段?
发布时间:2020-12-20 11:11:52 所属栏目:Python 来源:网络整理
导读:我正在尝试扩展 django的contrib.auth用户模型,使用内联“Profile”模型来包含额外的字段. from django.contrib import adminfrom django.contrib.auth.models import Userfrom django.contrib.auth.admin import UserAdminclass Profile(models.Model): use
我正在尝试扩展
django的contrib.auth用户模型,使用内联“Profile”模型来包含额外的字段.
from django.contrib import admin from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin class Profile(models.Model): user = models.ForeignKey(User,unique=True,related_name='profile') avatar = '/images/avatar.png' nickname = 'Renz' class UserProfileInline(admin.StackedInline): model = Profile class UserProfileAdmin(UserAdmin): inlines = (UserProfileInline,) admin.site.unregister(User) admin.site.register(User,UserProfileAdmin) 这适用于管理员“更改用户”页面,但我找不到在list_display中添加内联模型字段的方法.只需在list_display中指定配置文件字段的名称就会出错:
我可以创建一个callable,它在Profile表中查找用户并返回相关字段,但这使我无法通过内联字段对列表视图进行排序,我真的需要这样做. 有什么建议? 解决方法
你提到了唯一的解决方案 – 创建一个可调用的.目前没有其他方法可以做到这一点,是的,这确实意味着你不能按该列排序.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – 如何在db更新后获得SQLAlchemy ORM对象的先前状
- Python socket.error: [Errno 98] Address already in use的
- python+opencv实现动态物体识别
- eclipse for python
- 详解字典树Trie结构及其Python代码实现
- 为什么list [-1:1]在python中为空?
- python3-cookbook笔记:第四章 迭代器与生成器
- Python3网络爬虫实战-9、APP爬取相关库的安装:Appium的安装
- python – NLTK的XMLCorpusReader可用于多文件语料库吗?
- 基于Python实现的ID3决策树功能示例