问题描述
我知道您可以根据其他字段预填充管理表单字段.例如,我有一个基于标题字段自动填充的 slug 字段.
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.
我还想要一个文本字段,它会自动以你好,我的名字是作者"之类的内容开头,其中作者是当前用户的姓名.当然,我也希望此人能够编辑该字段.重点是让用户可以更轻松地填写管理表单,而不仅仅是拥有完全自动的字段.
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 - 如何预填充管理表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!