I am somewhat new at Django. I am writing an inventory app and have models for Assets, AssetTypes, and AssetSubTypes. Each asset can only have one type assigned, but can have many subtypes. I have a one to many relationship between the types and subtypes. For example, I have a type “Hookup Wire” and related subtypes “16 AWG, 18 AWG, 22 AWG, jumper, speaker, AC, DC, 12vac, 120vac”. There are other types and subtypes.
At the moment, I am using the admin site to add some items to my database. When adding an asset, I want to select one type using a drop-down combobox. Once selected, I want a list_display to show only the related subtypes.
I have searched for over a week for a solution but everything I find either deals with showing just one option in a combobox, like in a one to one relationship, or a long-winded solution using ajax, etc.
Is there a simple way to use what the type combobox selection is in the list_display list_filter?
I can post code if needed but based on my explanation, a point to a ModelAdmin method would be a good start for where I can look. If not, I can post code. It’s just long as there are a lot of model fields and models.
Thank you for your time! I appreciate it!
Your alternative is to do complete page refreshes, where a person selecting a type then goes to a page showing the subtypes for that page, and so on. (If your page is small enough and quick enough, it actually works out rather well.)
Thank you sir. That did clarify quite a bit for me, and gave me an idea on how to do it. The only reason I am using the admin site for now is that I have not progressed to views and the site pages yet. So I am not sure it is worth the effort (yet) to do this on my temporary way (using the admin site) of editing the database data.
So if I were to do it, I could wait for the page to finish rendering, then attach an event to the AssetType combo box. When it changes, I can use the selection to change the AssetSubType list_display’s contents. I would have to dig deeper if I wanted to pre-select the rows that were already assigned to that Asset item. I have done this sort of thing before on a solution I wrote from scratch, but never with or inside Django though.
Thank you for your reply! I will post back on what I decide to do and how I did it, and flag your reply as the solution at that time.