重写django管理视图时,如何获取对象信息?
我从管理站点选择一个对象(SourceClass 类型)并进入“更改”页面。
我选择的对象与另一种类型的对象 (TargetClass) 具有外键关系。
SourceClass 类型的对象的更改页面为我提供了一个下拉框(来自选择表单字段)和一个用于添加新 TargetClass 的链接。
添加链接的 URL 为: http://localhost:8000/admin/app/sourceclass/add/
通常的行为是我选择添加链接,创建一个新的 TargetClass 对象(在打开的弹出窗口中),然后单击“保存”后,我的 SourceClass 对象与我的新 TargetClass 对象相关。
现在,我想添加一些额外的步骤(例如通过表单向导),而不是仅仅要求用户为 TargetClass 添加字段值。
到目前为止,我已经更新了我的 urls.conf,
url(r'^admin/app/targetclass/add/$', 'proj.app.views.myaddmethod', name = 'myaddmethod'),
当我的方法“myaddmethod”被调用时,这工作得很好。 但是,我如何在方法“myaddmethod”中知道调用 add 的 SourceClass 的特定实例。
我的问题是,我如何知道在我的新视图中使用了 SourceClass 的哪个实例?我希望我会在 POST 数据中看到这一点,但它不在那里。
I select an object (of type SourceClass) from the admin site and get to the 'change' page.
The object I have selected has a ForeignKey relationship to another type of object (TargetClass).
The change page for the object of type SourceClass gives me both a drop down box (from a select form field) and a link to add a new TargetClass.
The url for the add link is:
http://localhost:8000/admin/app/sourceclass/add/
The usual behaviour is that I select the add link, create a new TargetClass object (in the pop up window that opens) and after 'Save' is clicked on, my SourceClass object is related to my new TargetClass object.
Now instead of just asking the user to add values for fields for TargetClass, I want to add a few extra steps (e.g. via form wizard).
So far I have updated my urls.conf with
url(r'^admin/app/targetclass/add/
This works fine as my method 'myaddmethod' is called.
However, how do I know in the method 'myaddmethod' the particular instance of SourceClass on which the add was called.
My question is, how can I know in my new view which instance of SourceClass was used ? I expect that I would see this in POST data, but it is not there.
, 'proj.app.views.myaddmethod', name = 'myaddmethod'),
This works fine as my method 'myaddmethod' is called.
However, how do I know in the method 'myaddmethod' the particular instance of SourceClass on which the add was called.
My question is, how can I know in my new view which instance of SourceClass was used ? I expect that I would see this in POST data, but it is not there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是添加方法。该对象尚未创建。导入模型并将表单传递到新模板中,然后通过发布提供数据并保存。
This is add method. The object is not created yet. Do import you model and pass form into new template, then give data via post and save it.