Friday, May 27, 2011

Django admin and jQuery select filtering

Hi,

First of all I will start by saying that I am fairly new to django, jQuery and javascript, but have been using python for a number of years now.  In order to get to know django, I thought I would try to develop a ladder application to display player rankings for my local squash club.  As part of this I wanted to add some ajax to some of my forms in the django admin in order to dynamically filter some of the options in a select box depending on the users selection in the previous box.  For example, when adding a new player to a ladder, it makes little sense to allow the user to select a player who is already a member of that ladder.  In order to do this, I have created a new model form as shown here: http://pastebin.com/y2uZxmnF.  I then wrote the following javascript (selectfilter.js): http://pastebin.com/vyHXzMH2.  Finally I wrote a view to select the required objects: http://pastebin.com/D2JVNHxS.

This works great, however, I need to use the same kind of functionality on other forms, but there is a lot hardcoded in to the javascript file and view so would require a new javascript file for each new form.  So I was wondering if there was a good way to make this more dynamic so the same code could be used for most (if not all) forms?

Any help would be greatly appreciated.

Many thanks,

Ryan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment