django admin外键字段数据添加 [英] django admin foreign key field data add

查看:1479
本文介绍了django admin外键字段数据添加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在django管理员中的任何应用程序的添加表单中,对于该模型的外键字段..有一个带有添加按钮(在弹出窗口中打开)的下拉列表。我们可以有一个表单,我们可以以相同的形式添加外键模型字段。

In add form for any app in django admin, for foreign key fields of that model.. comes a dropdown list with add button(which opens in a pop-up). Can we have a form where we can add the foreign key model fields in the same form.

例如

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    contact = models.ForeignKey(Contact, blank=True, null=True)

对于用户和联系人字段,添加按钮的下拉列表以管理员添加表单存在。我们可以在同一页面中拥有所有用户和联系领域吗?

For user and contact fields a dropdown with add button is present in admin add form.Can we have all fields of user and contact in same page??

推荐答案

是的,您可以使用内联管理系统

Yes, you can do that using the inline admin system.

class UserAdmin(admin.StackedInline):
    model = User
class ContactAdmin(admin.StackedInline):
    model = Contact

class UserProfileAdmin(admin.ModelAdmin):
    inlines = [ UserAdmin, ContactAdmin ]

有关详情,请查看ħ ttps://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

for more details check out https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects .

这篇关于django admin外键字段数据添加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆