From df38afa36b9cd78cfea8cd4ab09335882daf2967 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Mon, 11 Nov 2019 15:27:58 +0300 Subject: [PATCH] refactored a little model Product --- apps/product/admin.py | 4 +-- .../migrations/0010_auto_20191111_1227.py | 33 +++++++++++++++++++ apps/product/models.py | 9 +++-- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 apps/product/migrations/0010_auto_20191111_1227.py diff --git a/apps/product/admin.py b/apps/product/admin.py index 143d3ee9..3ad78409 100644 --- a/apps/product/admin.py +++ b/apps/product/admin.py @@ -10,8 +10,8 @@ class ProductAdmin(BaseModelAdminMixin, admin.ModelAdmin): search_fields = ('name', ) list_filter = ('available', 'product_type') list_display = ('id', '__str__', 'get_category_display', 'product_type') - raw_id_fields = ('country', 'subtypes', 'classifications', - 'standards', 'tags', 'gallery') + raw_id_fields = ('subtypes', 'classifications', 'standards', + 'tags', 'gallery') @admin.register(ProductType) diff --git a/apps/product/migrations/0010_auto_20191111_1227.py b/apps/product/migrations/0010_auto_20191111_1227.py new file mode 100644 index 00000000..774422c5 --- /dev/null +++ b/apps/product/migrations/0010_auto_20191111_1227.py @@ -0,0 +1,33 @@ +# Generated by Django 2.2.7 on 2019-11-11 12:27 + +from django.db import migrations, models +import utils.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0009_auto_20191111_0731'), + ] + + operations = [ + migrations.RemoveField( + model_name='product', + name='country', + ), + migrations.AlterField( + model_name='product', + name='available', + field=models.BooleanField(default=True, verbose_name='available'), + ), + migrations.AlterField( + model_name='product', + name='description', + field=utils.models.TJSONField(blank=True, default=None, help_text='{"en-GB":"some text"}', null=True, verbose_name='description'), + ), + migrations.AlterField( + model_name='product', + name='slug', + field=models.SlugField(max_length=255, null=True, unique=True, verbose_name='Slug'), + ), + ] diff --git a/apps/product/models.py b/apps/product/models.py index 1098252e..9950ad34 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -141,11 +141,9 @@ class Product(TranslatedFieldsMixin, BaseAttributes): name = models.CharField(max_length=255, default=None, null=True, verbose_name=_('name')) - description = TJSONField(_('Description'), null=True, blank=True, + description = TJSONField(_('description'), null=True, blank=True, default=None, help_text='{"en-GB":"some text"}') - country = models.ManyToManyField('location.Country', - verbose_name=_('Country')) - available = models.BooleanField(_('Available'), default=True) + available = models.BooleanField(_('available'), default=True) product_type = models.ForeignKey(ProductType, on_delete=models.PROTECT, null=True, related_name='products', verbose_name=_('Type')) @@ -177,7 +175,7 @@ class Product(TranslatedFieldsMixin, BaseAttributes): blank=True, null=True, verbose_name=_('wine appellation')) slug = models.SlugField(unique=True, max_length=255, null=True, - verbose_name=_('Establishment slug')) + verbose_name=_('Slug')) favorites = generic.GenericRelation(to='favorites.Favorites') old_id = models.PositiveIntegerField(_('old id'), default=None, blank=True, null=True) @@ -195,6 +193,7 @@ class Product(TranslatedFieldsMixin, BaseAttributes): validators=[MinValueValidator(EARLIEST_VINTAGE_YEAR), MaxValueValidator(LATEST_VINTAGE_YEAR)]) gallery = models.ManyToManyField('gallery.Image', through='ProductGallery') + reviews = generic.GenericRelation(to='review.Review') objects = ProductManager.from_queryset(ProductQuerySet)()