0

I have 3 models as such:

class Customer (models.Model):
     name = models.CharField (max_length = 20)

class Vehicle (models.Model):
     make = models.CharField (max_length = 20)
     customer = models.ForeignKey(Customer)

class Appointment (models.Model):
    customer = models.ForeignKey (Customer)
    vehicle = models.ForeignKey (Vehicle)

In the Appointment admin site, it currently shows me two dropdown lists, one showing all customers and the other showing all vehicles.

I want to implement it such that I first pick a customer, and then the second dropdown list is populated with a list of vehicles the customer owns. I know how to do this in a standard template with jQuery, but I can't find any documentation about how to do this in the admin site.

blinduck
  • 428
  • 1
  • 5
  • 20
  • possible duplicate of [Django admin. Displaying a hierarchical dropdown filter](http://stackoverflow.com/questions/4917893/django-admin-displaying-a-hierarchical-dropdown-filter) – Burhan Khalid Aug 29 '12 at 04:57
  • Hi, I've seen that question but no information about how to write custom widgets there either.. – blinduck Aug 29 '12 at 05:00
  • See http://stackoverflow.com/questions/1671446/country-state-city-dropdown-menus-inside-the-django-admin-inline then :) – Burhan Khalid Aug 29 '12 at 05:02

1 Answers1

0

https://github.com/digi604/django-smart-selects

EDIT: There's also a small app which provides a widget that you can use in django admin, and which doesn't require changes to the model (ChainedForeignKey etc.).

https://github.com/runekaagaard/django-admin-flexselect

Danny W. Adair
  • 12,498
  • 4
  • 43
  • 49
  • This works great for regular sites with templates, my question is more about how I would integrate this into the admin site.. – blinduck Aug 29 '12 at 06:02
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – edorian Aug 29 '12 at 08:23
  • @edorian the linked page doesn't contain an answer, but rather, an app that provides what blinduck is after. On top of the link I could only think of DIY instructions or an explanation on how that app works internally. With blinduck's emphasis on admin integration, I've added another link and this time I mentioned what to expect on that page. – Danny W. Adair Aug 29 '12 at 22:53
  • @Danny Thanks! That's pretty much exactly what I was looking for. Much appreciated. – blinduck Aug 30 '12 at 05:09