我可以使用Django的默认管理员应用程序来使用此模型吗? [英] Can I use the Django's default admin app for this model?

查看:147
本文介绍了我可以使用Django的默认管理员应用程序来使用此模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <$ 

c $ c> class A(models.Model):
name = models.TextField()

class B(models.Model):
related_A = models.ForeignKey(A )
info = models.TextField()

class C(models.Model):
related_B = models.ForeignKey(B)
other_infos = models.TextField )

所以A由一些B组成,由一些Cs组成。由于Django管理员不接受嵌套的在线表单,我认为这样做的理想方式是使用这种工作流程:将有一个管理页面,这将给我一个链接点击称为添加一些B到这个A,并提供一个带有B表格的页面使用内联C表单。



有没有办法这样做只是从管理网站,我没有看到,还是应该考虑延长管理员的默认应用程序?



某些澄清



。请假设你统计大陆,国家和地区。我的目标是建立一个明确的结构,将一个国家加入一个大陆和一个地区到一个国家。理想情况下,管理界面的用户将无法立即添加一个国家/地区;她或他需要经过一个他必须选择大陆的页面。理想情况下,大陆将有一页,其中包含一个内联形式的国家,每一种形式都有内联形式的区域。



由于嵌套的内联表单似乎不是Django 1.3中的一项功能,我正在寻找一种在管理网站中拥有工作流的方法:用户首先在第一个屏幕上点击大陆;它将显示一个大陆的清单;点击一个大陆将显示与该大陆相关联的国家的列表;最后,用户可以编辑一个国家表单,显示一些内联区域表单,以允许在同一页面上添加国家和地区。



我希望这个具体的例子可以更容易理解...

解决方案

最简单的方法是使用 Country 一个起点:在其表单页面中,您可以内联编辑 Region 以及强制员工从现有的大陆中选择或者通过点击 + 添加新的。



您还可以修改 ModelAdmin 打开国家页面,并填充已保存的大陆 pk c $ c>它更难。检查这个帖子也可以。



此外,可以模仿一个 ForeignKey C 中的 A ,并在 B C A 中,就像 GenericForeignKey 一样。但是,对于大多数用法来说,这是很困难和过度的...


Part of the model of an app I'm trying to build with django is based on a three-tier structure, like this :

 class A(models.Model):
     name = models.TextField()

 class B(models.Model):
     related_A = models.ForeignKey(A)
     info = models.TextField()

 class C(models.Model):
     related_B = models.ForeignKey(B)
     other_infos = models.TextField()

So A is composed of some Bs, which are composed of some Cs. Since Django admin doesn't accept nested inline forms yet, I was thinking the ideal way of doing it would be with this sort of workflow : there would be a "A admin page", which would get me a link to click called "Add some Bs to this A", and offer me a page with a B form using inline C forms.

Is there a way to do this simply from the Admin website that I didn't see, or should I consider extending the admin default application ?

Some clarification

Let's say you make statistics about Continent, Countries and Regions. My goal is to have a clear structure to add a Country to a Continent and a Region to a Country. Ideally, a user of the administration interface won't be able to add "immediately" a Country ; she or he needs to go through a page where he'll have to select a Continent. Ideally, there would be one single page for the Continent, containing an inline form of country, each of those forms having an inline form of regions.

Since nested inline forms do not seem to be a feature in Django 1.3, I'm looking for a way to have a sort of "workflow" in the administration site : the user would first click on "Continent" in the first screen ; it would then show a list of continents ; clicking on a continent would show a list of the countries associated to this continent ; finally, the user could edit a Country form, displaying some inline region forms to allow adding country and region on the same page.

I hope this concrete exemple make it easier to understand...

解决方案

The easiest way is to use Country as a start point: in its form page you could inline edit Region as well as force staff to choose from existed Continents or add new one by clicking +.

You could also modify ModelAdmin to open Country page and populate pk of a saved Continent to it, which is more difficult. Check this post also.

Furthermore, it's possible to mimic a ForeignKey pointing to A in C, and inline editing both B and C in A, just as GenericForeignKey does. However, it's hard and overkilled for most usages...

这篇关于我可以使用Django的默认管理员应用程序来使用此模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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