Prepopulate drop-box according to another drop-box choice in Django Admin

Posted by onorua on Stack Overflow See other posts from Stack Overflow or by onorua
Published on 2010-06-08T19:40:36Z Indexed on 2010/06/08 19:42 UTC
Read the original article Hit count: 276

Filed under:
|
|

I have models like this:

class User(models.Model): Switch = models.ForeignKey(Switch, related_name='SwitchUsers') Port = models.ForeignKey(Port) class Switch(models.Model): Name = models.CharField(max_length=50) class Port(models.Model): PortNum = models.PositiveIntegerField() Switch = models.ForeignKey(Switch, related_name = "Ports")

When I'm in Admin interface and choose Switch from Switches available, I would like to have Port prepopulated accordingly with Ports from the related Switch. As far as I understand I need to create some JS script to prepopulate it. Unfortunately I don't have this experience, and I would like to keep things simple as it possible and don't rewrite all Django admin interface. Just add this functionality for one Field.

Could you please help me with my problem? Thank you.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about python