You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the tutorial explains, you should be able to get rid of the Product model altogether, and make ProductVariant be the actual product. Imagine single item stock, such as original art pieces for sale. There will be no variants, and it does not make sense to "add" a variant when entering a new art piece for sale.
I tried modifying as little as possible to get started and changing references to the Product model to reference ProductVariant, however if it I get this error when running makemigrations:
ERRORS:
?: (wagtailcore.E002) Invalid subpage_types setting for <class 'catalog.models.ProductIndex'>
HINT: <class 'catalog.models.ProductVariant'> is not a Page subclass
catalog.ProductImage.product: (modelcluster.E001) ParentalKey must point to a subclass of ClusterableModel.
HINT: Change catalog.ProductVariant into a ClusterableModel or use a ForeignKey instead.
Here's models.py:
from django.db import models
from django_extensions.db.fields import AutoSlugField
from modelcluster.fields import ParentalKey
from wagtail.core.models import Page, Orderable
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from wagtail.images.edit_handlers import ImageChooserPanel
from longclaw.products.models import ProductVariantBase, ProductBase
class ProductIndex(Page):
"""Index page for all products
"""
subpage_types = ('catalog.ProductVariant', 'catalog.ProductIndex')
# class Product(ProductBase):
# parent_page_types = ['catalog.ProductIndex']
# description = RichTextField()
# content_panels = ProductBase.content_panels + [
# FieldPanel('description'),
# InlinePanel('images', label='Images'),
# InlinePanel('variants', label='Product variants'),
# ]
# @property
# def first_image(self):
# return self.images.first()
class ProductVariant(ProductVariantBase):
"""Represents a 'variant' of a product
"""
# You *could* do away with the 'Product' concept entirely - e.g. if you only
# want to support 1 'variant' per 'product'.
# product = ParentalKey(Product, related_name='variants')
# slug = AutoSlugField(
# separator='',
# populate_from=('product', 'ref'),
# )
# Enter your custom product variant fields here
# e.g. colour, size, stock and so on.
# Remember, ProductVariantBase provides 'price', 'ref' and 'stock' fields
description = RichTextField()
class ProductImage(Orderable):
"""Example of adding images related to a product model
"""
product = ParentalKey(ProductVariant, related_name='images')
image = models.ForeignKey('wagtailimages.Image', on_delete=models.CASCADE, related_name='+')
caption = models.CharField(blank=True, max_length=255)
panels = [
ImageChooserPanel('image'),
FieldPanel('caption')
]
The text was updated successfully, but these errors were encountered:
ISSUE_TEMPLATE
Description
As the tutorial explains, you should be able to get rid of the Product model altogether, and make ProductVariant be the actual product. Imagine single item stock, such as original art pieces for sale. There will be no variants, and it does not make sense to "add" a variant when entering a new art piece for sale.
I tried modifying as little as possible to get started and changing references to the Product model to reference ProductVariant, however if it I get this error when running makemigrations:
Here's models.py:
The text was updated successfully, but these errors were encountered: