Add to shopping cart related questions


I have a question about how to implementing add a item to shopping cart function on a e-commerce website, there are some Django tutorial online shows how to write add_to_cart function for a online store, but on those tutorial they only show how to get item from one model. What if a online store has multiple category products and they use different Models to represent different category products, how do I use only one add_to_cart function to get what ever category product I need? Or I have to write multiple add_to_cart function for each category (Model) to make it work?


Write your function to do whatever you need it to do.

It’s going to be really tough answering your questions in detail without knowing the specific add_to_cart function being used or the tutorial you’re getting your information from.

But in general, add_to_cart is either going to be a view, or be a function being called from a view. Either way, it doesn’t matter. You access data the same way you would in any other view or function. Using it in a shopping cart / e-commerce application doesn’t change anything.