简体   繁体   English

Django Admin和Dajax

[英]Django Admin and Dajax

I am new to using anything ajax related, so please excuse my ignorance. 我不熟悉任何与ajax相关的东西,所以请原谅我的无知。

I am working with the example here and trying to get it to work in the Django Admin. 我在这里使用示例并尝试使其在Django Admin中运行。 I am working on creating a custom change form for the model it will be used in. 我正在为将使用的模型创建自定义更改表单。

The problem I am having is that after making the selection in the first selection box, nothing happens with the second box. 我遇到的问题是,在第一个选择框中进行选择后,第二个框什么也没有发生。 I have tried using both prototype and jquery, but it seems that it doesn't get to either of them. 我曾尝试使用原型和jquery,但似乎都无法使用它们。
One thing I had to do to even get it to call the function in ajax.py, is I had to add quotes around the Dajax.process variable being passed within onchange. 为了使它能够调用ajax.py中的函数,我必须要做的一件事就是我必须在onchange中传递的Dajax.process变量周围添加引号。

I am currently just using the django dev server for testing purposes. 我目前仅将django开发服务器用于测试目的。

What am I missing? 我想念什么?

So, there are several things you'll need to make work together in order to do this: 因此,您需要一起做几件事才能做到这一点:

At minimum: 至少:

  • A URL pattern to handle your request. URL模式来处理您的请求。
  • A view method to return the data in 一种视图方法,用于返回数据
    whatever form you need. 您需要的任何形式。
  • A JavaScript file that has the event handlers you need, which you can add through a form's Media property, or by including it in the change form template. 一个具有所需事件处理程序的JavaScript文件,您可以通过表单的Media属性或将其包含在更改表单模板中来添加该事件处理程序。

Possibly: 可能:

  • A template to override the built-in admin template to suit your needs. 覆盖内置管理模板以适合您需要的模板。
  • A custom form class to hold the value(s) you Ajax in. 一个定制表单类,用于保存您在Ajax中使用的值。

From there, you can use FireBug or Fiddler to make sure you're passing in, and getting back the right values from your Ajax call. 从那里,您可以使用FireBug或Fiddler来确保传入,并从Ajax调用中获取正确的值。

You'll also need to handle editing a record, where you'll need to fire an Ajax call to populate your dynamic form based on the existing value of the object. 您还需要处理一条记录,在该记录中,您需要触发Ajax调用以根据对象的现有值填充动态表单。

Happy coding! 编码愉快!

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

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