Let’s suppose we have these three models:
- cagegory ( id, name )
- subcategory ( id, id_category, name )
- product ( id, id_sub_category, name )
with 30 categories, each category has 30 subcategories and each subcategory has 50 products.
Total products = 30 x 30 x 50 = 45000
Then, in severals views of django project I want to include a product selection.
What is the most djangonic solution to implement the product selection?
There’s nothing built into Django that’s going to solve this use case for you, however, you can use a combination of things in Django to make this work.
I’m assuming you want your product selection to go like this:
string resulting from the rendering of another view that contains
a drop-down for the sub category, filtered by the category.
You’re going to need to use a combination of views, forms and some JavaScript to make this work. There are some nice plugins for jQuery to submit forms via Ajax. Views can return HTML rendered as a string, which you can pop into the DOM, and you should only need one event listener attached to the select(s) that submits their parent form to the URL that will process the POST.
Hope that gets you on the right track.