Search code examples
pythonajaxdjangodjango-admindjango-views

Django admin add form ajax call


So I've had success with Django/Ajax/Jquery before but I was wondering if I can do it within the admin console. When the user goes to the "Add New" form, I want them to fill out the ZIP code and based on that zip code, filter the available choices in the next field based upon the values I have in the database that correspond to that ZIP code.

I'm trying to look for the admin view that handles the POST for that form but I'm relatively new to django and am having troubles locating it. Maybe I'm overthinking this and there is an easier solution?


Solution

    1. Create a view that, given a zipcode, responds with a json list of available choices (python)
    2. Override the admin template for the model that has the zip code field (templates)
    3. Add a listener to the zipcode's keyup or change event, that queries the view and uses the response to filter the next field (javascript)