简体   繁体   中英

Django Admin and Dajax

I am new to using anything ajax related, so please excuse my ignorance.

I am working with the example here and trying to get it to work in the 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.
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.

I am currently just using the django dev server for testing purposes.

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.
  • 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.

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.

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.

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.

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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