Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to "do away with Product completely"? #327

Open
jeffykle opened this issue Aug 9, 2020 · 0 comments
Open

How to "do away with Product completely"? #327

jeffykle opened this issue Aug 9, 2020 · 0 comments

Comments

@jeffykle
Copy link

jeffykle commented Aug 9, 2020

ISSUE_TEMPLATE

  • longclaw version: 1.0.2
  • Django version: 3.0.9
  • Python version: 3.6.10

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:

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')
    ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant