Merge branch 'develop' into feature/migrate-news
This commit is contained in:
commit
647147bf03
44
apps/collection/migrations/0015_auto_20191023_0715.py
Normal file
44
apps/collection/migrations/0015_auto_20191023_0715.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 07:15
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
import utils.models
|
||||||
|
|
||||||
|
|
||||||
|
def fill_title_json_from_title(apps, schema_editor):
|
||||||
|
# We can't import the Person model directly as it may be a newer
|
||||||
|
# version than this migration expects. We use the historical version.
|
||||||
|
Collection = apps.get_model('collection', 'Collection')
|
||||||
|
for collection in Collection.objects.all():
|
||||||
|
collection.name_json = {'en-GB': collection.name}
|
||||||
|
collection.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('collection', '0014_auto_20191022_1242'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name_json',
|
||||||
|
field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='name'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(fill_title_json_from_title, migrations.RunPython.noop),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name',
|
||||||
|
),
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='collection',
|
||||||
|
old_name='name_json',
|
||||||
|
new_name='name',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='collection',
|
||||||
|
name='name',
|
||||||
|
field=utils.models.TJSONField(help_text='{"en-GB":"some text"}', verbose_name='name'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -43,9 +43,11 @@ class CollectionQuerySet(RelatedObjectsCountMixin):
|
||||||
return self.filter(is_publish=True)
|
return self.filter(is_publish=True)
|
||||||
|
|
||||||
|
|
||||||
class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
class Collection(ProjectBaseMixin, CollectionDateMixin,
|
||||||
TranslatedFieldsMixin, URLImageMixin):
|
TranslatedFieldsMixin, URLImageMixin):
|
||||||
"""Collection model."""
|
"""Collection model."""
|
||||||
|
STR_FIELD_NAME = 'name'
|
||||||
|
|
||||||
ORDINARY = 0 # Ordinary collection
|
ORDINARY = 0 # Ordinary collection
|
||||||
POP = 1 # POP collection
|
POP = 1 # POP collection
|
||||||
|
|
||||||
|
|
@ -54,6 +56,8 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
||||||
(POP, _('Pop')),
|
(POP, _('Pop')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
name = TJSONField(verbose_name=_('name'),
|
||||||
|
help_text='{"en-GB":"some text"}')
|
||||||
collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES,
|
collection_type = models.PositiveSmallIntegerField(choices=COLLECTION_TYPES,
|
||||||
default=ORDINARY,
|
default=ORDINARY,
|
||||||
verbose_name=_('Collection type'))
|
verbose_name=_('Collection type'))
|
||||||
|
|
@ -79,10 +83,6 @@ class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin,
|
||||||
verbose_name = _('collection')
|
verbose_name = _('collection')
|
||||||
verbose_name_plural = _('collections')
|
verbose_name_plural = _('collections')
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
"""String method."""
|
|
||||||
return f'{self.name}'
|
|
||||||
|
|
||||||
|
|
||||||
class GuideQuerySet(models.QuerySet):
|
class GuideQuerySet(models.QuerySet):
|
||||||
"""QuerySet for Guide."""
|
"""QuerySet for Guide."""
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,19 @@ from rest_framework import serializers
|
||||||
|
|
||||||
from collection import models
|
from collection import models
|
||||||
from location import models as location_models
|
from location import models as location_models
|
||||||
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
||||||
class CollectionBaseSerializer(serializers.ModelSerializer):
|
class CollectionBaseSerializer(serializers.ModelSerializer):
|
||||||
"""Collection base serializer"""
|
"""Collection base serializer"""
|
||||||
# RESPONSE
|
name_translated = TranslatedField()
|
||||||
description_translated = serializers.CharField(read_only=True, allow_null=True)
|
description_translated = TranslatedField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Collection
|
model = models.Collection
|
||||||
fields = [
|
fields = [
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name_translated',
|
||||||
'description_translated',
|
'description_translated',
|
||||||
'image_url',
|
'image_url',
|
||||||
'slug',
|
'slug',
|
||||||
|
|
@ -35,8 +36,7 @@ class CollectionSerializer(CollectionBaseSerializer):
|
||||||
queryset=location_models.Country.objects.all(),
|
queryset=location_models.Country.objects.all(),
|
||||||
write_only=True)
|
write_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta(CollectionBaseSerializer.Meta):
|
||||||
model = models.Collection
|
|
||||||
fields = CollectionBaseSerializer.Meta.fields + [
|
fields = CollectionBaseSerializer.Meta.fields + [
|
||||||
'start',
|
'start',
|
||||||
'end',
|
'end',
|
||||||
|
|
|
||||||
18
apps/establishment/migrations/0041_auto_20191023_0920.py
Normal file
18
apps/establishment/migrations/0041_auto_20191023_0920.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 09:20
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('establishment', '0040_employee_tags'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='establishment',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Establishment slug'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -349,8 +349,8 @@ class Establishment(ProjectBaseMixin, URLImageMixin, TranslatedFieldsMixin):
|
||||||
verbose_name=_('Collections'))
|
verbose_name=_('Collections'))
|
||||||
preview_image_url = models.URLField(verbose_name=_('Preview image URL path'),
|
preview_image_url = models.URLField(verbose_name=_('Preview image URL path'),
|
||||||
blank=True, null=True, default=None)
|
blank=True, null=True, default=None)
|
||||||
slug = models.SlugField(unique=True, max_length=50, null=True,
|
slug = models.SlugField(unique=True, max_length=255, null=True,
|
||||||
verbose_name=_('Establishment slug'), editable=True)
|
verbose_name=_('Establishment slug'))
|
||||||
|
|
||||||
awards = generic.GenericRelation(to='main.Award', related_query_name='establishment')
|
awards = generic.GenericRelation(to='main.Award', related_query_name='establishment')
|
||||||
tags = models.ManyToManyField('tag.Tag', related_name='establishments',
|
tags = models.ManyToManyField('tag.Tag', related_name='establishments',
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,12 @@ class EstablishmentMixinView:
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Overridden method 'get_queryset'."""
|
"""Overridden method 'get_queryset'."""
|
||||||
return models.Establishment.objects.published() \
|
qs = models.Establishment.objects.published() \
|
||||||
.with_base_related() \
|
.with_base_related() \
|
||||||
.annotate_in_favorites(self.request.user)
|
.annotate_in_favorites(self.request.user)
|
||||||
|
if self.request.country_code:
|
||||||
|
qs = qs.by_country_code(self.request.country_code)
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
||||||
|
|
@ -30,13 +33,6 @@ class EstablishmentListView(EstablishmentMixinView, generics.ListAPIView):
|
||||||
filter_class = filters.EstablishmentFilter
|
filter_class = filters.EstablishmentFilter
|
||||||
serializer_class = serializers.EstablishmentBaseSerializer
|
serializer_class = serializers.EstablishmentBaseSerializer
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""Overridden method 'get_queryset'."""
|
|
||||||
qs = super(EstablishmentListView, self).get_queryset()
|
|
||||||
if self.request.country_code:
|
|
||||||
qs = qs.by_country_code(self.request.country_code)
|
|
||||||
return qs
|
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentRetrieveView(EstablishmentMixinView, generics.RetrieveAPIView):
|
class EstablishmentRetrieveView(EstablishmentMixinView, generics.RetrieveAPIView):
|
||||||
"""Resource for getting a establishment."""
|
"""Resource for getting a establishment."""
|
||||||
|
|
|
||||||
14
apps/main/migrations/0020_merge_20191023_0750.py
Normal file
14
apps/main/migrations/0020_merge_20191023_0750.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 07:50
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0019_award_image_url'),
|
||||||
|
('main', '0019_auto_20191022_1359'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
18
apps/main/migrations/0021_auto_20191023_0924.py
Normal file
18
apps/main/migrations/0021_auto_20191023_0924.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 09:24
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0020_merge_20191023_0750'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='feature',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=255, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -182,7 +182,7 @@ class Page(models.Model):
|
||||||
class Feature(ProjectBaseMixin, PlatformMixin):
|
class Feature(ProjectBaseMixin, PlatformMixin):
|
||||||
"""Feature model."""
|
"""Feature model."""
|
||||||
|
|
||||||
slug = models.CharField(max_length=255, unique=True)
|
slug = models.SlugField(max_length=255, unique=True)
|
||||||
priority = models.IntegerField(unique=True, null=True, default=None)
|
priority = models.IntegerField(unique=True, null=True, default=None)
|
||||||
route = models.ForeignKey(Page, on_delete=models.PROTECT, null=True, default=None)
|
route = models.ForeignKey(Page, on_delete=models.PROTECT, null=True, default=None)
|
||||||
site_settings = models.ManyToManyField(SiteSettings, through='SiteFeature')
|
site_settings = models.ManyToManyField(SiteSettings, through='SiteFeature')
|
||||||
|
|
|
||||||
18
apps/news/migrations/0023_auto_20191023_0903.py
Normal file
18
apps/news/migrations/0023_auto_20191023_0903.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-10-23 09:03
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('news', '0022_auto_20191021_1306'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='news',
|
||||||
|
name='slug',
|
||||||
|
field=models.SlugField(max_length=255, unique=True, verbose_name='News slug'),
|
||||||
|
),
|
||||||
|
]
|
||||||
7
apps/product/apps.py
Normal file
7
apps/product/apps.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class ProductConfig(AppConfig):
|
||||||
|
name = 'product'
|
||||||
|
verbose_name = _('Product')
|
||||||
110
apps/product/models.py
Normal file
110
apps/product/models.py
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
"""Product app models."""
|
||||||
|
from django.db import models
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from utils.models import (BaseAttributes, ProjectBaseMixin,
|
||||||
|
TranslatedFieldsMixin, TJSONField)
|
||||||
|
|
||||||
|
|
||||||
|
class ProductType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||||
|
"""ProductType model."""
|
||||||
|
|
||||||
|
name = TJSONField(blank=True, null=True, default=None,
|
||||||
|
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'))
|
||||||
|
use_subtypes = models.BooleanField(_('Use subtypes'), default=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
verbose_name = _('Product type')
|
||||||
|
verbose_name_plural = _('Product types')
|
||||||
|
|
||||||
|
|
||||||
|
class ProductSubType(TranslatedFieldsMixin, ProjectBaseMixin):
|
||||||
|
"""ProductSubtype model."""
|
||||||
|
|
||||||
|
product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE,
|
||||||
|
related_name='subtypes',
|
||||||
|
verbose_name=_('Product type'))
|
||||||
|
name = TJSONField(blank=True, null=True, default=None,
|
||||||
|
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 Meta:
|
||||||
|
"""Meta class."""
|
||||||
|
|
||||||
|
verbose_name = _('Product type')
|
||||||
|
verbose_name_plural = _('Product types')
|
||||||
|
|
||||||
|
|
||||||
|
class ProductManager(models.Manager):
|
||||||
|
"""Extended manager for Product model."""
|
||||||
|
|
||||||
|
|
||||||
|
class ProductQuerySet(models.QuerySet):
|
||||||
|
"""Product queryset."""
|
||||||
|
|
||||||
|
def common(self):
|
||||||
|
return self.filter(category=self.model.COMMON)
|
||||||
|
|
||||||
|
def online(self):
|
||||||
|
return self.filter(category=self.model.ONLINE)
|
||||||
|
|
||||||
|
|
||||||
|
class Product(TranslatedFieldsMixin, BaseAttributes):
|
||||||
|
"""Product models."""
|
||||||
|
|
||||||
|
COMMON = 0
|
||||||
|
ONLINE = 1
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
from django.apps import AppConfig
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
|
|
||||||
class ProductsConfig(AppConfig):
|
|
||||||
"""Products model."""
|
|
||||||
name = 'products'
|
|
||||||
verbose_name = _('products')
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
# from django.contrib.postgres.fields import JSONField
|
|
||||||
# from django.db import models
|
|
||||||
# from django.utils.translation import gettext_lazy as _
|
|
||||||
#
|
|
||||||
# from utils.models import BaseAttributes
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ProductManager(models.Manager):
|
|
||||||
# """Product manager."""
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ProductQuerySet(models.QuerySet):
|
|
||||||
# """Product queryset."""
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class Product(BaseAttributes):
|
|
||||||
# """Product models."""
|
|
||||||
# name = models.CharField(_('name'), max_length=255)
|
|
||||||
# country = models.ForeignKey('location.Country', on_delete=models.CASCADE)
|
|
||||||
# region = models.ForeignKey('location.Region', on_delete=models.CASCADE)
|
|
||||||
# # ASK: What is the "subregion"
|
|
||||||
#
|
|
||||||
# description = JSONField(_('description'))
|
|
||||||
# characteristics = JSONField(_('characteristics'))
|
|
||||||
# metadata_values = JSONField(_('metadata_values'))
|
|
||||||
# # common_relations_id
|
|
||||||
# # product_region_id
|
|
||||||
# code = models.CharField(_('code'), max_length=255)
|
|
||||||
# available = models.BooleanField(_('available'))
|
|
||||||
#
|
|
||||||
# # dealer_type
|
|
||||||
# # target_scope
|
|
||||||
# # target_type
|
|
||||||
# # rank
|
|
||||||
# # excluding_tax_unit_price
|
|
||||||
# # column_21
|
|
||||||
# # currencies_id
|
|
||||||
# # vintage
|
|
||||||
# # producer_price
|
|
||||||
# # producer_description
|
|
||||||
# # annual_produced_quantity
|
|
||||||
# # production_method_description
|
|
||||||
# # unit_name
|
|
||||||
# # unit
|
|
||||||
# # unit_values
|
|
||||||
# # organic_source
|
|
||||||
# # certificates
|
|
||||||
# # establishments_id
|
|
||||||
# # restrictions
|
|
||||||
# #
|
|
||||||
# objects = ProductManager.from_queryset(ProductQuerySet)()
|
|
||||||
#
|
|
||||||
# class Meta:
|
|
||||||
# verbose_name = _('product')
|
|
||||||
# verbose_name_plural = _('products')
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# class ProductType(models.Model):
|
|
||||||
# """ProductType model."""
|
|
||||||
#
|
|
||||||
# class Meta:
|
|
||||||
# verbose_name_plural = _('product types')
|
|
||||||
# verbose_name = _('product type')
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
# Create your views here.
|
|
||||||
|
|
@ -64,6 +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', 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',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user