0
衆所周知,在django管理站點中添加新用戶後,頁面被重定向到編輯配置文件,而不是像其他模型那樣的用戶列表頁面。如何在普通模型中實現這一點?例如,我定義了一個名爲Image的模型,並希望在圖像上傳後編輯圖像。如何在django管理站點中實現像用戶模型一樣的普通模型管理器
衆所周知,在django管理站點中添加新用戶後,頁面被重定向到編輯配置文件,而不是像其他模型那樣的用戶列表頁面。如何在普通模型中實現這一點?例如,我定義了一個名爲Image的模型,並希望在圖像上傳後編輯圖像。如何在django管理站點中實現像用戶模型一樣的普通模型管理器
把下面的函數放到你的管理類中。
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)