对于django模型,如何获取django admin URL来添加另一个或列表对象等? [英] For a django model, how can I get the django admin URL to add another, or list objects, etc.?

查看:207
本文介绍了对于django模型,如何获取django admin URL来添加另一个或列表对象等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢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?

推荐答案

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 admin URL来添加另一个或列表对象等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆