简体   繁体   English

django admin中的详细对象模板

[英]Detail object template in django admin

I am customizing django admin and I would like to have some template of an object's detail. 我正在自定义django admin,并且我想要一些对象详细信息的模板。 Just like the "edit" template but without editable fields. 就像“编辑”模板一样,但是没有可编辑的字段。

In CRUD philosophy the Read web page. 在CRUD哲学中,阅读网页。

Is there any snippet, package or some advice about this? 是否有任何摘要,包装或一些建议?

Thanks! 谢谢!

Not directly in the standard Django admin 不直接在标准Django管理员中

But if you define the get_absolute_url method on your model you will get a "View on site" button in the admin 但是,如果您在模型上定义get_absolute_url方法,则将在管理中获得“查看站点”按钮

So this is a mechanism you can use to provide your own view (eg DetailView ) for the 'Read' 因此,这是一种可用于为“读取”提供自己的视图(例如DetailView )的机制

Thanks Anentropic for this answer 感谢Anentropic的答案

I had to create a DetailView, I let my code here for future visitors: 我必须创建一个DetailView,将代码留给以后的访问者:

class UsersDetailView(DetailView):

    model = Users
    template_name = 'users_detail.html'

It is very minimalist. 这是非常简约的。

You can also add the model parameter in urls.py so the view can be generic. 您还可以在urls.py添加model参数,以便视图可以通用。 Like this: 像这样:

from app_name.models import GenericDetailView

urlpatterns = patterns('',
    (r'^proj/app_name/(?P<object_name>users)/(?P<pk>[0-9]+)/detail$', GenericDetailView.as_view(model=Users)),
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM