]> git.parisson.com Git - mezzo.git/commitdiff
Create ProductBlock and related page inline
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 23 Sep 2016 15:40:59 +0000 (17:40 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 23 Sep 2016 15:40:59 +0000 (17:40 +0200)
app/organization/pages/admin.py
app/organization/shop/admin.py
app/organization/shop/migrations/0001_initial.py [new file with mode: 0644]
app/organization/shop/models.py
app/organization/shop/translation.py

index 1cbf8b3c09ecfd6f9420344735206bf757c03ccb..17d3dcd9bf02f7aaeafe29fb2929cd9e99335e9b 100644 (file)
@@ -12,6 +12,8 @@ from organization.pages.models import (
 from organization.pages.forms import *
 from organization.network.forms import *
 from organization.network.models import PageCustomPersonListBlockInline
+from organization.shop.models import *
+
 
 class PageBlockInline(StackedDynamicInlineAdmin):
 
@@ -46,6 +48,11 @@ class PersonListBlockAutocompleteInlineAdmin(TabularDynamicInlineAdmin):
     form = PageCustomPersonListForm
 
 
+class PageProductBlockInline(TabularDynamicInlineAdmin):
+
+    model = PageProductBlock
+
+
 class CustomPageAdmin(PageAdmin):
 
     inlines = [PageBlockInline,
@@ -54,6 +61,7 @@ class CustomPageAdmin(PageAdmin):
             PageVideoInline,
             PageLinkInline,
             PersonListBlockAutocompleteInlineAdmin,
+            PageProductBlockInline
             ]
 
 
index 0d9f2e2062ca7d651426ac23f259c705cb4675e4..26c2b9a5ab8b919c2cf807fa419200ede2cacff4 100644 (file)
@@ -8,3 +8,17 @@ from mezzanine.core.admin import *
 from organization.projects.models import *
 from organization.pages.models import *
 from organization.media.models import Video, Audio
+from organization.shop.models import *
+
+
+class ProductBlockProductInline(StackedDynamicInlineAdmin):
+
+    model = ProductBlockProduct
+
+
+class ProductBlockAdmin(admin.ModelAdmin):
+
+    inlines = [ProductBlockProductInline]
+
+
+admin.site.register(ProductBlock, ProductBlockAdmin)
diff --git a/app/organization/shop/migrations/0001_initial.py b/app/organization/shop/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..fc64e2e
--- /dev/null
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-23 15:40
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        ('shop', '0008_auto_20160907_1726'),
+        ('organization-pages', '0002_auto_20160914_1838'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='PageProductBlock',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('page', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='product_blocks', to='organization-pages.CustomPage', verbose_name='page')),
+            ],
+            options={
+                'verbose_name': 'product block',
+                'verbose_name_plural': 'product blocks',
+            },
+        ),
+        migrations.CreateModel(
+            name='ProductBlock',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('title', models.CharField(max_length=1024, verbose_name='title')),
+                ('title_fr', models.CharField(max_length=1024, null=True, verbose_name='title')),
+                ('title_en', models.CharField(max_length=1024, null=True, verbose_name='title')),
+                ('description', models.TextField(blank=True, verbose_name='description')),
+                ('style', models.CharField(choices=[('square', 'square'), ('circle', 'circle')], max_length=16, verbose_name='style')),
+            ],
+            options={
+                'verbose_name': 'product block',
+                'verbose_name_plural': 'product blocks',
+            },
+        ),
+        migrations.CreateModel(
+            name='ProductBlockProduct',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('_order', mezzanine.core.fields.OrderField(null=True, verbose_name='Order')),
+                ('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='blocks', to='shop.Product', verbose_name='product')),
+                ('product_block', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='products', to='organization-shop.ProductBlock', verbose_name='product block')),
+            ],
+            options={
+                'verbose_name': 'product',
+                'verbose_name_plural': 'products',
+                'ordering': ('_order',),
+            },
+        ),
+        migrations.AddField(
+            model_name='pageproductblock',
+            name='product_block',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='pages', to='organization-shop.ProductBlock', verbose_name='product block'),
+        ),
+    ]
index cd51d4c3c6955b94f5c750073f25fe435e3957d4..86f19a65853b25cbc77c85f78e5f49efac14e6ba 100644 (file)
@@ -4,6 +4,45 @@ from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
 from mezzanine.core.models import RichText, Displayable, Slugged, Orderable
+from cartridge.shop.models import Product
 
 from organization.core.models import *
-from organization.pages.models import *
+
+
+PRODUCT_LIST_STYLE_CHOICES = [
+    ('square', _('square')),
+    ('circle', _('circle')),
+]
+
+
+class ProductBlock(Titled):
+
+    style = models.CharField(_('style'), max_length=16, choices=PRODUCT_LIST_STYLE_CHOICES)
+
+    class Meta:
+        verbose_name = _("product block")
+        verbose_name_plural = _("product blocks")
+
+    def __str__(self):
+        return self.title
+
+
+class ProductBlockProduct(Orderable):
+
+    product_block = models.ForeignKey(ProductBlock, verbose_name=_('product block'), related_name='products', blank=True, null=True, on_delete=models.SET_NULL)
+    product = models.ForeignKey(Product, verbose_name=_('product'), related_name='blocks', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = _("product")
+        verbose_name_plural = _("products")
+
+
+
+class PageProductBlock(models.Model):
+
+    page = models.ForeignKey('organization-pages.CustomPage', verbose_name=_('page'), related_name='product_blocks', blank=True, null=True, on_delete=models.SET_NULL)
+    product_block = models.ForeignKey('organization-shop.ProductBlock', verbose_name=_('product block'), related_name='pages', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = _("product block")
+        verbose_name_plural = _("product blocks")
index 60c2e5d333a199c92f3e9b12ab1aadd13ded500f..37da75baea0c54fbfb6c90c4b48d771782b21163 100644 (file)
@@ -1,11 +1,22 @@
 from modeltranslation.translator import translator, register, TranslationOptions
 
-from organization.projects.models import *
+from organization.shop.models import *
 
 
-# @register(Project)
-# class ProjectTranslationOptions(TranslationOptions):
-#
-#     fields = ('title', 'description', 'content')
-#
-#
+
+@register(ProductBlock)
+class ProductBlockTranslationOptions(TranslationOptions):
+
+    fields = ['title',]
+
+
+@register(ProductBlockProduct)
+class ProductBlockProductTranslationOptions(TranslationOptions):
+
+    pass
+
+
+@register(PageProductBlock)
+class PageProductBlockTranslationOptions(TranslationOptions):
+
+    pass