How to have multiple product variant models?
See original GitHub issueHi,
I have some trouble grasping the concept of modeling a catalog with different variant requirements.
How would one create a catalog with multiple ProductVariant
models?
For example if I would have both mobile phones and t-shirts in a catalogue:
# Shirt product
class Shirt(ProductBase):
description = RichTextField()
# Other shirt fields
content_panels = ProductBase.content_panels + [
FieldPanel('description'),
InlinePanel('variants', label='Product variants'),
]
class ShirtVariant(ProductVariantBase):
COLORS = [('red', 'Red'), ('green', 'Green'), ('blue', 'Blue')]
product = ParentalKey(Shirt, related_name='variants')
shirt_color = models.CharField(choices=COLORS, default='blue')
# Phone product
class Phone(ProductBase):
description = RichTextField()
# Other phone fields
content_panels = ProductBase.content_panels + [
FieldPanel('description'),
InlinePanel('variants', label='Product variants'),
]
class PhoneVariant(ProductVariantBase):
CAPACITIES = [('32', '32 G'), ('64', '64 G'), ('128', '128 G')]
product = ParentalKey(Phone, related_name='variants')
phone_capacity = models.CharField(choices=CAPACITIES, default='32')
I have noticed that PRODUCT_VARIANT_MODEL
setting is required, and I realise this is not the intended use of the ProductVariant
model. Reading through the docs I’ve failed to understand how to achieve a similar catalog model.
Any explanation would be much appreciated. Thanks =)
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
Design Guidelines for Selling Products with Multiple Variants
Different products should have different listings; product variations should be displayed under a single listing.
Read more >Adding variants - Shopify Help Center
If your variants differ in more than one way, then tap Add another option. You can have up to 3 options for each...
Read more >Modeling Product Variants - mysql - Stack Overflow
A product can have 0 or more product variants (e.g. a t-shirt product may have size and color variants). · A product variant...
Read more >Products and variants | Tutorials
When deciding to use product variants, try multiplying the variable attributes with each other. This gives a rough idea of how many variants...
Read more >How to Set Up Product Options - The Complete Guide to ...
Certain products need to have options in eCommerce, like apparel of different colors and sizes. Here's how to add product variations to your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having re-read the initial question, I think this is just a case of making your variant models more dynamic.
There isn’t any difference between a
Shirt
product and aPhone
in how you have defined it, so we can keep the standard product class:we might want to enrich it with a ‘category’ field.
Now we want a variant model, where we can choose what we use for the ‘choices’. Django has something builtin for that - the ModelChoiceField
We can then make any number of separate models for different types of variants. The idea is to make the product/variant as generic and configurable as possible (balanced against ease of use) so that when you have a new product type you can just add it in the admin.
@tboulogne @dinoperovic I have plans to be spending some time around this in a couple of months once some obligations are cleared. Please share any progress you made here and your approach. What made the implementation difficult for you? Is there anything in particular that would ease your troubles?