diff --git a/apps/location/models.py b/apps/location/models.py index fc81ec37..5624d068 100644 --- a/apps/location/models.py +++ b/apps/location/models.py @@ -138,14 +138,13 @@ class WineRegionQuerySet(models.QuerySet): """Wine region queryset.""" -class WineRegion(TranslatedFieldsMixin, models.Model): +class WineRegion(models.Model): """Wine region model.""" - STR_FIELD_NAME = 'name' - - name = TJSONField(verbose_name=_('Name'), - help_text='{"en-GB":"some text"}') + name = models.CharField(_('name'), max_length=255) country = models.ForeignKey(Country, on_delete=models.PROTECT, verbose_name=_('country')) + coordinates = models.PointField( + _('Coordinates'), blank=True, null=True, default=None) objects = WineRegionQuerySet.as_manager() @@ -155,26 +154,47 @@ class WineRegion(TranslatedFieldsMixin, models.Model): verbose_name = _('wine region') -class WineAppellationQuerySet(models.QuerySet): - """Wine appellation queryset.""" +class WineSubRegionQuerySet(models.QuerySet): + """Wine sub region QuerySet.""" -class WineAppellation(TranslatedFieldsMixin, models.Model): - """Wine appellation model.""" - STR_FIELD_NAME = 'name' +class WineSubRegion(models.Model): + """Wine sub region model.""" + name = models.CharField(_('name'), max_length=255) + country = models.ForeignKey(Country, on_delete=models.PROTECT, + verbose_name=_('country')) - name = TJSONField(verbose_name=_('Name'), - help_text='{"en-GB":"some text"}') - wine_region = models.ForeignKey(WineRegion, on_delete=models.PROTECT, - related_name='appellations', - verbose_name=_('wine region')) - - objects = WineAppellationQuerySet.as_manager() + objects = WineSubRegionQuerySet.as_manager() class Meta: """Meta class.""" - verbose_name_plural = _('wine appellations') - verbose_name = _('wine appellation') + verbose_name_plural = _('wine regions') + verbose_name = _('wine region') + + +class WineVillageQuerySet(models.QuerySet): + """Wine village QuerySet.""" + + +class WineVillage(models.Model): + """ + Wine village. + Description: Imported from legacy DB. + """ + name = models.CharField(_('name'), max_length=255) + description = TJSONField(verbose_name=_('description'), + help_text='{"en-GB":"some text"}') + wine_region = models.ForeignKey(WineRegion, on_delete=models.PROTECT, + verbose_name=_('wine region')) + wine_sub_region = models.ForeignKey(WineSubRegion, on_delete=models.PROTECT, + verbose_name=_('wine sub region')) + + objects = WineVillageQuerySet.as_manager() + + class Meta: + """Meta class.""" + verbose_name = _('wine village') + verbose_name_plural = _('wine villages') # todo: Make recalculate price levels diff --git a/apps/product/models.py b/apps/product/models.py index 332a92f6..a4f5a120 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -1,5 +1,6 @@ """Product app models.""" from django.db import models +from django.contrib.gis.db import models as gis_models from django.contrib.contenttypes import fields as generic from django.core.exceptions import ValidationError from django.contrib.postgres.fields import JSONField @@ -157,9 +158,9 @@ class Product(TranslatedFieldsMixin, BaseAttributes): related_name='wines', blank=True, null=True, verbose_name=_('wine region')) - wine_appellation = models.ForeignKey('location.WineAppellation', on_delete=models.PROTECT, - blank=True, null=True, - verbose_name=_('wine appellation')) + wine_standard = models.ForeignKey('product.WineStandard', on_delete=models.PROTECT, + blank=True, null=True, + verbose_name=_('wine appellation')) slug = models.SlugField(unique=True, max_length=255, null=True, verbose_name=_('Establishment slug')) favorites = generic.GenericRelation(to='favorites.Favorites') @@ -202,3 +203,54 @@ class OnlineProduct(Product): proxy = True verbose_name = _('Online product') verbose_name_plural = _('Online products') + + +class WineStandardQuerySet(models.QuerySet): + """Wine appellation queryset.""" + + +class WineStandard(models.Model): + """Wine standard model.""" + + APPELLATION = 'Appellation' + CLASSIFICATION = 'Classification' + WINEQUALITY = 'WineQuality' + YARDCLASSIFICATION = 'YardClassification' + + STANDARDS = ( + (APPELLATION, _('Appellation')), + (CLASSIFICATION, _('Classification')), + (WINEQUALITY, _('Wine quality')), + (YARDCLASSIFICATION, _('Yard classification')), + ) + + name = models.CharField(_('name'), max_length=255) + standard_type = models.CharField(max_length=30, choices=STANDARDS, + verbose_name=_('standard type')) + coordinates = gis_models.PointField( + _('Coordinates'), blank=True, null=True, default=None) + + objects = WineStandardQuerySet.as_manager() + + class Meta: + """Meta class.""" + verbose_name_plural = _('wine standards') + verbose_name = _('wine standard') + + +class WineClassificationQuerySet(models.QuerySet): + """Wine classification QuerySet.""" + + +class WineClassification(models.Model): + """Wine classification model.""" + name = models.CharField(_('name'), max_length=255) + standard = models.ForeignKey(WineStandard, on_delete=models.PROTECT, + verbose_name=_('standard')) + + objects = WineClassificationQuerySet.as_manager() + + class Meta: + """Meta class.""" + verbose_name = _('wine classification') + verbose_name_plural = _('wine classifications') diff --git a/apps/product/transfer_data.py b/apps/product/transfer_data.py new file mode 100644 index 00000000..e69de29b