问题描述
我喜欢django文档,部分是奇怪的。
As much as I love the django documentation, the section on bookmarklets in the admin is strangely vague.
我的问题是:如果我在一个视图我有一个django模型(或在某些情况下,一个实际的对象),我该如何获得该模型(或对象)的相关管理页面?如果我有对象coconut_transportation.swallow.objects.all()[34],我怎么可以直接跳到管理页面来编辑特定的燕子?
My question is this: If I'm in a view and I have a django model (or, in some cases, an actual object), how can I get to the relevant admin pages for that model (or object)? If I have the object coconut_transportation.swallow.objects.all()[34], how can I jump right to the admin page to edit that particular swallow?
同样,如何获取管理页面的URL来添加另一个燕子?
Likewise, how can I get the URL for the admin page to add another swallow?
推荐答案
obj = coconut_transportation.swallow.objects.all()[34]
# list url
url = reverse("admin:coconut_transportation_swallow_changelist")
# change url
url = reverse("admin:coconut_transportation_swallow_change", args=[obj.id])
# add url
url = reverse("admin:coconut_transportation_swallow_add")
这篇关于对于django模型,如何获取django admin URL来添加另一个或列表对象等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!