Models created: Product, OnlineProduct (proxy), ProductType, ProductSubtype

This commit is contained in:
evgeniy-st 2019-10-23 11:31:45 +03:00
parent 1b9df7c713
commit 766b6659f1
2 changed files with 111 additions and 64 deletions

View File

@ -1,63 +1,110 @@
# from django.contrib.postgres.fields import JSONField """Product app models."""
# from django.db import models from django.db import models
# from django.utils.translation import gettext_lazy as _ from django.contrib.postgres.fields import JSONField
# from django.utils.translation import gettext_lazy as _
# from utils.models import BaseAttributes from utils.models import (BaseAttributes, ProjectBaseMixin,
# TranslatedFieldsMixin, TJSONField)
#
# class ProductManager(models.Manager):
# """Product manager.""" class ProductType(TranslatedFieldsMixin, ProjectBaseMixin):
# """ProductType model."""
#
# class ProductQuerySet(models.QuerySet): name = TJSONField(blank=True, null=True, default=None,
# """Product queryset.""" verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
# index_name = models.CharField(max_length=50, unique=True, db_index=True,
# verbose_name=_('Index name'))
# class Product(BaseAttributes): use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
# """Product models."""
# name = models.CharField(_('name'), max_length=255) class Meta:
# country = models.ForeignKey('location.Country', on_delete=models.CASCADE) """Meta class."""
# region = models.ForeignKey('location.Region', on_delete=models.CASCADE)
# # ASK: What is the "subregion" verbose_name = _('Product type')
# verbose_name_plural = _('Product types')
# description = JSONField(_('description'))
# characteristics = JSONField(_('characteristics'))
# metadata_values = JSONField(_('metadata_values')) class ProductSubType(TranslatedFieldsMixin, ProjectBaseMixin):
# # common_relations_id """ProductSubtype model."""
# # product_region_id
# code = models.CharField(_('code'), max_length=255) product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE,
# available = models.BooleanField(_('available')) related_name='subtypes',
# verbose_name=_('Product type'))
# # dealer_type name = TJSONField(blank=True, null=True, default=None,
# # target_scope verbose_name=_('Name'), help_text='{"en-GB":"some text"}')
# # target_type index_name = models.CharField(max_length=50, unique=True, db_index=True,
# # rank verbose_name=_('Index name'))
# # excluding_tax_unit_price
# # column_21 class Meta:
# # currencies_id """Meta class."""
# # vintage
# # producer_price verbose_name = _('Product type')
# # producer_description verbose_name_plural = _('Product types')
# # annual_produced_quantity
# # production_method_description
# # unit_name class ProductManager(models.Manager):
# # unit """Extended manager for Product model."""
# # unit_values
# # organic_source
# # certificates class ProductQuerySet(models.QuerySet):
# # establishments_id """Product queryset."""
# # restrictions
# # def common(self):
# objects = ProductManager.from_queryset(ProductQuerySet)() return self.filter(category=self.model.COMMON)
#
# class Meta: def online(self):
# verbose_name = _('product') return self.filter(category=self.model.ONLINE)
# verbose_name_plural = _('products')
#
# class Product(TranslatedFieldsMixin, BaseAttributes):
# class ProductType(models.Model): """Product models."""
# """ProductType model."""
# COMMON = 0
# class Meta: ONLINE = 1
# verbose_name_plural = _('product types')
# verbose_name = _('product type') CATEGORY_CHOICES = (
(COMMON, _('Common')),
(ONLINE, _('Online')),
)
category = models.PositiveIntegerField(choices=CATEGORY_CHOICES,
default=COMMON)
name = TJSONField(_('Name'), null=True, blank=True, default=None,
help_text='{"en-GB":"some text"}')
description = TJSONField(_('Description'), null=True, blank=True,
default=None, help_text='{"en-GB":"some text"}')
characteristics = JSONField(_('Characteristics'))
country = models.ForeignKey('location.Country', on_delete=models.PROTECT,
verbose_name=_('Country'))
available = models.BooleanField(_('Available'), default=True)
type = models.ForeignKey(ProductType, on_delete=models.PROTECT,
related_name='products', verbose_name=_('Type'))
subtypes = models.ManyToManyField(ProductSubType, related_name='products',
verbose_name=_('Subtypes'))
objects = ProductManager.from_queryset(ProductQuerySet)()
class Meta:
"""Meta class."""
verbose_name = _('Product')
verbose_name_plural = _('Products')
class OnlineProductManager(ProductManager):
"""Extended manger for OnlineProduct model."""
def get_queryset(self):
"""Overrided get_queryset method."""
return super().get_queryset().online()
class OnlineProduct(Product):
"""Online product."""
objects = OnlineProductManager.from_queryset(ProductQuerySet)()
class Meta:
"""Meta class."""
proxy = True
verbose_name = _('Online product')
verbose_name_plural = _('Online products')

View File

@ -64,7 +64,7 @@ PROJECT_APPS = [
'news.apps.NewsConfig', 'news.apps.NewsConfig',
'notification.apps.NotificationConfig', 'notification.apps.NotificationConfig',
'partner.apps.PartnerConfig', 'partner.apps.PartnerConfig',
'product.apps.ProductConfig', # 'product.apps.ProductConfig', Uncomment after refining task and create migrations
'recipe.apps.RecipeConfig', 'recipe.apps.RecipeConfig',
'search_indexes.apps.SearchIndexesConfig', 'search_indexes.apps.SearchIndexesConfig',
'translation.apps.TranslationConfig', 'translation.apps.TranslationConfig',