简体   繁体   English

django:为模型创建子模型

[英]django: create submodel for a model

在此处输入图片说明

How to create a model like the image where I can add as many players as I want from admin-panel? 如何创建一个像图片一样的模型,在其中我可以从管理面板中添加任意数量的玩家? I think players is a sub-model but I have no idea how to add multiple record at a time alongside the main model 我认为玩家是一个子模型,但我不知道如何在主模型的同时添加多个记录

You need to set up the Players model as a many-to-one with the parent model and then use InlineModelAdmin to view this in the admin. 您需要将播放器模型与父模型设置为多对一,然后使用InlineModelAdmin在管理员中查看。

You can refer to - https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#inlinemodeladmin-objects 您可以参考-https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#inlinemodeladmin-objects

The solution is given in the documentation: https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.TabularInline 该解决方案在文档中给出: https : //docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.TabularInline

as Higor Rossato mentioned in the comment 正如Higor Rossato在评论中提到的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM