Django - 如何预填充管理表单字段 [英] Django - How to prepopulate admin form fields

查看:209
本文介绍了Django - 如何预填充管理表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以根据其他字段预先填写管理表单字段。例如,我有一个根据标题字段自动填充的s条字段。

I know that you can prepopulate admin form fields based on other fields. For example, I have a slug field that is automatically populated based on the title field.

但是,我也想根据日期进行其他自动预填充。例如,我有一个URL字段,我希望它自动设置为 http://example.com/20090209 .mp3 其中20090209是YYYYMMDD。

However, I would also like to make other automatic prepopulations based on the date. For example, I have an URL field, and I want it to automatically be set to http://example.com/20090209.mp3 where 20090209 is YYYYMMDD.

我也想要一个文本字段,自动以Hello我的名字是作者开头,其中作者是当前用户的名字。当然,我也希望该人能够编辑该字段。关键是要让用户更容易地填写管理表单,而不仅仅是让字段是完全自动的。

I would also like to have a text field that automatically starts with something like "Hello my name is author" where author is the current user's name. Of course, I also want the person to be able to edit the field. The point is to just make it so the user can fill out the admin form more easily, and not just to have fields that are completely automatic.

推荐答案

我知道你可以通过GET预先填写一些值,这样就可以这样。

I know that you can prepopulate some values via GET, it will be something like this

http://localhost:8000/admin/app/model/add/?model_field=hello

日期字段,但也许这可以帮助您。

I got some problems with date fields but, maybe this could help you.

这篇关于Django - 如何预填充管理表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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