如何从Django的TabularInline管理视图中省略对象名称? [英] How to omit object name from Django's TabularInline admin view?

查看:1512
本文介绍了如何从Django的TabularInline管理视图中省略对象名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Django的 TabularInline 管理视图来编辑与主题对象相关的类别对象,如下所示:

I'm using Django's TabularInline admin view to edit category objects related to a main topic object, as shown here:

是有一种方法来显示对象的渲染名称(本例中的常规问题,媒体处理和边距等),不使用创建自定义管理模板?换句话说,我只想显示一个干净的输入字段网格。

Is there a way to not show the rendered names of the objects ("General Questions", "Media Handling and Margins", etc. in this example), without creating a custom admin template? In other words, I just want to show a clean grid of input fields.

我发现了相关的渲染代码这里,在这个片段:

I found the relevant rendering code here, at this fragment:

   ...
        <td class="original">
          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
          {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
            </p>{% endif %}
   ...

有一个简短的,聪明的方式省略 {{inline_admin_form.original}} 或让它返回Null?

Is there a short, clever way to omit the {{ inline_admin_form.original }} or have it return Null?

推荐答案

我以为我会改变你的模板是最简单的。

I thought I'd chime in that editing your template is going to be the easiest.

我尝试在 render_change_form 但不幸的是,主要的问题是, InlineAdminForm 是在模板中的迭代动态构建的,所以你不能只设置 inlineadminform.original =无或修改上下文。

I tried iterating over the formsets in render_change_form but unfortunately, the major problem is that InlineAdminForms are constructed dynamically upon iteration in the template so you can't just set inlineadminform.original = None or modify the context.

他们甚至不存在直到屁股点击模板中的变量。

They don't even exist until assigned a variable in the template.

# InlineAdminFormset
def __iter__(self):
    for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()):
        yield InlineAdminForm(self.formset, form, self.fieldsets,
            self.opts.prepopulated_fields, original, self.readonly_fields,
            model_admin=self.model_admin)

和唯一容易的非黑客可访问的钩子我们有覆盖 InlineAdminFormset.formset.get_queryset()这会打破其他的事情。

and the only easily non-hackishly accessible hook we have there is overriding InlineAdminFormset.formset.get_queryset() which breaks other things.

我可以分享一些代码没有人应该真的看,但工作,让我开始笑起来?我欠你一个payne希望今晚能睡觉

Can I share some code nobody should ever really look at but works and makes me crack up laughing? I owe you one payne. Hope I can get to sleep tonight.

这篇关于如何从Django的TabularInline管理视图中省略对象名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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