English 中文(简体)
如何建立复杂的行政行动,需要补充资料?
原标题:How to create a complex admin action that requires additional information?

我很想为行政接口采取行动,除了选定项目之外还需要一些额外信息。 我的榜样是,在一系列活动中增加精华。 (我知道,显然的答案是,为了简单的例子,建立X-to-X关系的图谋,但与我有关系。)

在这个例子中,我发明了100个漫画。 在他们重新创建之后,我要向他们表示,他们已经制造了一系列目标。 为了在行政部门内开展这一行动,我要选择这些项目,然后采取行动。 然后,我要问一下哪一系列反对使用(通过注射、中间形式等)。

我是遵循以下指示的:here,其中声称通过中间形式实现这一点。 在与它合作之后,我不会再犯过错误,但行动本身也没有被执行,因为 for徒从未被处决。 相反,它用“选择不采取行动”的信息回到了admin的行政清单。

我的行政管理方法:

from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponseRedirect
def addSeries(self, request, queryset):
    form = None
    if  cancel  in request.POST:
        self.message_user(request,  Canceled series linking. )
        return
    elif  link_series  in request.POST:
        form = self.SeriesForm(request.POST)
        if form.is_valid():
            series = form.cleaned_data[ series ]
            for x in queryset:
                y = Link(series = series, comic = x)
                y.save()
            self.message_user(request, self.categorySuccess.render(Context({ count :queryset.count(),  series :series})))
            return HttpResponseRedirect(request.get_full_path())
    if not form:
        form = self.SeriesForm(initial={ _selected_action : request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})
    return render_to_response( setSeries.html , { comics : queryset,  form : form,  path :request.get_full_path()}, context_instance=RequestContext(request))
addSeries.short_description =  Set Series 

我的中间形式集聚物:

<!DOCTYPE html>
<html>
    <head>
        <title>Create Series Links</title>
    </head>
    <body>
        <h1>Create Series Links</h1>
        <p>Choose the series for the selected comic(s):</p>
        <form method="post" action="{{ path }}">
            <table>
                {{ form }}
            </table>
            <p>
                <input type="hidden" name="action" value="changeSeries" />
                <input type="submit" name="cancel" value="Cancel" />
                <input type="submit" name="link_series" value="link_series" />
            </p>
        </form>
        <h2>This categorization will affect the following:</h2>
        <ul>
            {% for comic in comics %}
                <li>{{ comic.title }}</li>
            {% endfor %}
        </ul>
    </body>
</html>
最佳回答

我注意到的一件事是,你的行动方法是“干s”,但以你称之为“变化”。

在您的《示范公约》中,你应当有这样的一行:

actions = [ addSeries ]

如果你有这种关系,那么你需要改变:

<input type="hidden" name="action" value="changeSeries" />

:

<input type="hidden" name="action" value="addSeries" />

Django的行政管理如何知道选择了哪些行动。 当你在选择行动和执行行动之间有中间形式时,你需要保留行政接口中选定的菜单。

问题回答

暂无回答




相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签