django-shop-tutorial
django-shop-tutorial copied to clipboard
Adding sizes to products
I have a small issue, I am wandering how I should implent product size functionality. I think adding such field to Product class inside shop/models.py is not fine, because how could I order two same items in different sizes? Mayby you know how to help
SIZES = (
('XS', 'XSmall'),
('S', 'Small'),
('M', 'Medium'),
('L', 'Large'),
)
size = models.CharField(max_length=2, choices=SIZES)
I don't know much about what you mean. If you want to have two same items in different sizes, there is a different item name.
Alright I think I've found what I was looking for: If anyone will be interested in the future:
Create another class Size, and add many to many field into Product https://stackoverflow.com/a/45947874/
Also, remember that Django creates a separate table for many to many field, which holds both FKeys https://stackoverflow.com/a/18144236/
And last thing, how to make queries https://stackoverflow.com/a/39677932/