List Info

Thread: Filter choices based on another selection in the Admin view




Filter choices based on another selection in the Admin view
country flaguser name
United States
2007-02-28 16:27:13
My application has companies and aircraft, where aircraft
has a
foreign key to a company. When a user is creating a trip,
both a
company and an aircraft can be selected from drop-down
lists. I'd like
to modify so that after the company is selected the choices
for
aircraft are only those aircraft that are associated with
the company
rather than the entire set. Ideas, please....


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


Re: Filter choices based on another selection in the Admin view
user name
2007-02-28 17:16:28
On 2/28/07, Jay <Jay.Bugenhagengmail.com> wrote:
>
> My application has companies and aircraft, where
aircraft has a
> foreign key to a company. When a user is creating a
trip, both a
> company and an aircraft can be selected from drop-down
lists. I'd like
> to modify so that after the company is selected the
choices for
> aircraft are only those aircraft that are associated
with the company
> rather than the entire set. Ideas, please....


In admin:
class Trip(...):
    ....
    class Admin:
       js = ['/your/js/to/do/filter.js/']

http://www.djangoproject.com/documentation/model_api/#js


But if not for admin, you can do a similarly unobtrusive
thing.  The
select element for the company will have an ID.  Hook the
change event
on it and re-fill the aircraft select elm using the json
results of a
xmlhttprequest to a custom view.

Check out django.core.serializers:
http://www.djangoproject.com/documentation/serializatio
n/

If that warning scares you, check out
django.utils.simplejson instead.  

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


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )