对于 django 模型,如何获取 django 管理 URL 以添加另一个或列出对象等? [英] For a django model, how can I get the django admin URL to add another, or list objects, etc.?
问题描述
尽管我很喜欢 django 文档,但 关于小书签的部分在管理员中 奇怪的模糊.
As much as I love the django documentation, the section on bookmarklets in the admin is strangely vague.
我的问题是:如果我在视图中并且我有一个 django 模型(或者,在某些情况下,是一个实际对象),我如何才能访问该模型(或对象)的相关管理页面?如果我有对象concept_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?
推荐答案
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#reversing-admin-urls
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 管理 URL 以添加另一个或列出对象等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!