Django admin - stackedInline 单实例
我正在构建一个基于高度定制的 django 管理实例的网站,并且遇到了用户配置文件作为 user_admin
长话短说的内联问题,无论我在 admin.StackedInline 实例中为 max_num 和 extra 设置了什么,它最多允许 2 个每个用户的配置文件 - 默认情况下有一个空白的,如果用户有现有的配置文件,
有人知道我如何调整它以仅显示一个内联配置文件,而不诉诸某些 JS 前端 hack 吗?
相关代码来自:profiles.admin.py
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from profile.models import user_profile
class user_profile_admin(admin.StackedInline):
model = user_profile
fk_name = 'user'
max_num = 1
extra = 0
class user_admin_extended(UserAdmin):
inlines = [user_profile_admin, ]
admin.site.unregister(User)
admin.site.register(User, user_admin_extended)
I'm building a site based on a highly customized django admin instance and am running into issues with user profiles as an inline to user_admin
long story short regardless of what I set for max_num and extra in the admin.StackedInline instance it allows up to 2 profiles per user - with a blank one in place by default if the user has an existing profile
anyone know how I could adjust this to show only a single inline profile without resorting to some JS front end hack?
relevant code from: profiles.admin.py
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from profile.models import user_profile
class user_profile_admin(admin.StackedInline):
model = user_profile
fk_name = 'user'
max_num = 1
extra = 0
class user_admin_extended(UserAdmin):
inlines = [user_profile_admin, ]
admin.site.unregister(User)
admin.site.register(User, user_admin_extended)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您使用 FK 字段来连接用户和配置文件?尝试 OneToOneField 它应该只在管理中呈现一个内联。
I assume you're using FK field to connect user and profile? Try OneToOneField it should render just one inline in admin.