django-shop-tutorial icon indicating copy to clipboard operation
django-shop-tutorial copied to clipboard

Adding sizes to products

Open mikazz opened this issue 5 years ago • 2 comments

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)

mikazz avatar Aug 26 '19 13:08 mikazz

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.

twtrubiks avatar Aug 28 '19 11:08 twtrubiks

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/

mikazz avatar Aug 28 '19 12:08 mikazz