0

众所周知,在 django 管理站点中添加新用户后,页面被重定向到编辑配置文件,而不是像其他模型那样的用户列表页面。如何在普通模型中实现这一点?例如,我定义了一个名为 Image 的模型,并想在图像上传后编辑图像。

4

1 回答 1

0

将以下函数放入您的管理类。

django/contrib/auth/admin.py:L139

def response_add(self, request, obj, post_url_continue='../%s/'):
    """
    Determines the HttpResponse for the add_view stage. It mostly defers to
    its superclass implementation but is customized because the User model
    has a slightly different workflow.
    """
    # We should allow further modification of the user just added i.e. the
    # 'Save' button should behave like the 'Save and continue editing'
    # button except in two scenarios:
    # * The user has pressed the 'Save and add another' button
    # * We are adding a user in a popup
    if '_addanother' not in request.POST and '_popup' not in request.POST:
        request.POST['_continue'] = 1
    return super(UserAdmin, self).response_add(request, obj, post_url_continue)
于 2012-07-19T07:51:59.217 回答