]> git.parisson.com Git - diggersdigest.git/commitdiff
Add extra field to BlogPost to handle products in news
authorThomas Fillon <thomas@parisson.com>
Wed, 9 Sep 2015 16:29:32 +0000 (18:29 +0200)
committerThomas Fillon <thomas@parisson.com>
Wed, 9 Sep 2015 16:29:32 +0000 (18:29 +0200)
diggersdigest/diggersdigest/local_settings.py
diggersdigest/diggersdigest/migrations/blog/0001_initial.py [new file with mode: 0644]
diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py [new file with mode: 0644]
diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py [new file with mode: 0644]
diggersdigest/diggersdigest/migrations/blog/__init__.py [new file with mode: 0644]
diggersdigest/diggersdigest/settings.py
diggersdigest/records/admin.py
diggersdigest/records/migrations/0010_auto_20150909_1400.py [new file with mode: 0644]
diggersdigest/records/models.py

index 14f5870d89e88838ac0da5d3edf741dae6eee86b..2c50da43010a5ab5292f9b563cb0a178e4b1bf12 100644 (file)
@@ -62,24 +62,12 @@ FILEBROWSER_SELECT_FORMATS = {
 # Add Migration Module path see : https://github.com/stephenmcd/mezzanine/blob/master/docs/model-customization.rst#field-injection-caveats
 MIGRATION_MODULES = {
     "shop": "diggersdigest.migrations.shop",
+    "blog": "diggersdigest.migrations.blog"
 }
 
 # USE or EXTEND the custom callback-uuid form
 SHOP_CHECKOUT_FORM_CLASS = 'payments.multipayments.forms.base.CallbackUUIDOrderForm'
 
-# Add the callback_uuid field to orders. This field is helpful for identifying
-# orders being checked out.
-EXTRA_MODEL_FIELDS = (
-# ...
-(
-"cartridge.shop.models.Order.callback_uuid",
-"django.db.models.CharField",
-(),
-{"blank" : False, "max_length" : 36},
-),
-# ...
-)
-
 PRIMARY_PAYMENT_PROCESSOR_IN_USE = True
 
 SECONDARY_PAYMENT_PROCESSORS = (
diff --git a/diggersdigest/diggersdigest/migrations/blog/0001_initial.py b/diggersdigest/diggersdigest/migrations/blog/0001_initial.py
new file mode 100644 (file)
index 0000000..1124f8b
--- /dev/null
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import mezzanine.core.fields
+import mezzanine.utils.models
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('sites', '0001_initial'),
+        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='BlogCategory',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('title', models.CharField(max_length=500, verbose_name='Title')),
+                ('slug', models.CharField(help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL', blank=True)),
+                ('site', models.ForeignKey(editable=False, to='sites.Site')),
+            ],
+            options={
+                'ordering': ('title',),
+                'verbose_name': 'Blog Category',
+                'verbose_name_plural': 'Blog Categories',
+            },
+            bases=(models.Model,),
+        ),
+        migrations.CreateModel(
+            name='BlogPost',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('comments_count', models.IntegerField(default=0, editable=False)),
+                ('keywords_string', models.CharField(max_length=500, editable=False, blank=True)),
+                ('rating_count', models.IntegerField(default=0, editable=False)),
+                ('rating_sum', models.IntegerField(default=0, editable=False)),
+                ('rating_average', models.FloatField(default=0, editable=False)),
+                ('title', models.CharField(max_length=500, verbose_name='Title')),
+                ('slug', models.CharField(help_text='Leave blank to have the URL auto-generated from the title.', max_length=2000, null=True, verbose_name='URL', blank=True)),
+                ('_meta_title', models.CharField(help_text='Optional title to be used in the HTML title tag. If left blank, the main title field will be used.', max_length=500, null=True, verbose_name='Title', blank=True)),
+                ('description', models.TextField(verbose_name='Description', blank=True)),
+                ('gen_description', models.BooleanField(default=True, help_text='If checked, the description will be automatically generated from content. Uncheck if you want to manually set a custom description.', verbose_name='Generate description')),
+                ('created', models.DateTimeField(null=True, editable=False)),
+                ('updated', models.DateTimeField(null=True, editable=False)),
+                ('status', models.IntegerField(default=2, help_text='With Draft chosen, will only be shown for admin users on the site.', verbose_name='Status', choices=[(1, 'Draft'), (2, 'Published')])),
+                ('publish_date', models.DateTimeField(help_text="With Published chosen, won't be shown until this time", null=True, verbose_name='Published from', blank=True)),
+                ('expiry_date', models.DateTimeField(help_text="With Published chosen, won't be shown after this time", null=True, verbose_name='Expires on', blank=True)),
+                ('short_url', models.URLField(null=True, blank=True)),
+                ('in_sitemap', models.BooleanField(default=True, verbose_name='Show in sitemap')),
+                ('content', mezzanine.core.fields.RichTextField(verbose_name='Content')),
+                ('allow_comments', models.BooleanField(default=True, verbose_name='Allow comments')),
+                ('featured_image', mezzanine.core.fields.FileField(max_length=255, null=True, verbose_name='Featured Image', blank=True)),
+                ('categories', models.ManyToManyField(related_name='blogposts', verbose_name='Categories', to='blog.BlogCategory', blank=True)),
+                ('related_posts', models.ManyToManyField(related_name='related_posts_rel_+', verbose_name='Related posts', to='blog.BlogPost', blank=True)),
+                ('site', models.ForeignKey(editable=False, to='sites.Site')),
+                ('user', models.ForeignKey(related_name='blogposts', verbose_name='Author', to=settings.AUTH_USER_MODEL)),
+            ],
+            options={
+                'ordering': ('-publish_date',),
+                'verbose_name': 'Blog post',
+                'verbose_name_plural': 'Blog posts',
+            },
+            bases=(models.Model, mezzanine.utils.models.AdminThumbMixin),
+        ),
+    ]
diff --git a/diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py b/diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py
new file mode 100644 (file)
index 0000000..a5cb65c
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('blog', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='blogpost',
+            name='publish_date',
+            field=models.DateTimeField(help_text="With Published chosen, won't be shown until this time", null=True, verbose_name='Published from', db_index=True, blank=True),
+        ),
+    ]
diff --git a/diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py b/diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py
new file mode 100644 (file)
index 0000000..3ae1fc5
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('shop', '0003_auto_20150906_1911'),
+        ('blog', '0002_auto_20150527_1555'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='blogpost',
+            name='related_products',
+            field=models.ManyToManyField(to='shop.Product', verbose_name=b'Related products', blank=True),
+        ),
+    ]
diff --git a/diggersdigest/diggersdigest/migrations/blog/__init__.py b/diggersdigest/diggersdigest/migrations/blog/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 3dd4ee001b0865f7a361e98cd42dbc43bbd700cc..c2868f8ed41828ad7e64788a4c75028e93e8700a 100644 (file)
@@ -128,25 +128,35 @@ SHOP_USE_VARIATIONS = False
 # field instance. When specifying the field class, the path
 # ``django.models.db.`` can be omitted for regular Django model fields.
 #
-# EXTRA_MODEL_FIELDS = (
-#     (
-#         # Dotted path to field.
-#         "mezzanine.blog.models.BlogPost.image",
-#         # Dotted path to field class.
-#         "somelib.fields.ImageField",
-#         # Positional args for field class.
-#         (_("Image"),),
-#         # Keyword args for field class.
-#         {"blank": True, "upload_to": "blog"},
-#     ),
-#     # Example of adding a field to *all* of Mezzanine's content types:
-#     (
-#         "mezzanine.pages.models.Page.another_field",
-#         "IntegerField", # 'django.db.models.' is implied if path is omitted.
-#         (_("Another name"),),
-#         {"blank": True, "default": 1},
-#     ),
-# )
+
+EXTRA_MODEL_FIELDS = (
+    (
+    # Dotted path to field.# Dotted path to field.
+    "mezzanine.blog.models.BlogPost.related_products",
+     # Dotted path to field class.
+     "django.db.models.ManyToManyField",
+     # Positional args for field class.
+     ("shop.Product",),
+     # Keyword args for field class.
+     {"verbose_name": ("Related products"), "blank": True},
+     ),
+     # Add the callback_uuid field to orders. This field is helpful for identifying
+     # orders being checked out.
+     (
+        "cartridge.shop.models.Order.callback_uuid",
+        "django.db.models.CharField",
+        (),
+        {"blank" : False, "max_length" : 36},
+     )
+     # ...
+     #     # Example of adding a field to *all* of Mezzanine's content types:
+     #     (
+     #         "mezzanine.pages.models.Page.another_field",
+     #         "IntegerField", # 'django.db.models.' is implied if path is omitted.
+     #         (_("Another name"),),
+     #         {"blank": True, "default": 1},
+     #     ),
+ )
 
 # Setting to turn on featured images for blog posts. Defaults to False.
 #
index 60fdfa5ea8091c8ca2479c2941bfc4dbdb4353d2..f2276a77b4ccb268dd80d7e968331c3f16484ab4 100644 (file)
@@ -1,7 +1,14 @@
+from copy import deepcopy
+
 from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
 from cartridge.shop.models import Product, ProductImage, ProductVariation
 from cartridge.shop.admin import ProductAdmin, ProductImageAdmin, ProductVariationAdmin
 
+from mezzanine.blog.admin import BlogPostAdmin
+from mezzanine.blog.models import BlogPost
+
 # Register your models here.
 from .models import Gallery
 from .models import Grading
@@ -30,6 +37,23 @@ class RecordAdmin(admin.ModelAdmin):
     search_fields = ["title", "artist__name", "label__name"]
     filter_horizontal = ["performers"]
 
+
+blog_fieldsets = deepcopy(BlogPostAdmin.fieldsets)
+blog_fieldsets.insert(1, (_("Related products"), {
+    "classes": ("collapse-closed",),
+    "fields": ("related_products",)}))
+blog_filter_horizontal = BlogPostAdmin.filter_horizontal
+blog_filter_horizontal += ("related_products", )
+
+
+class MyBlogPostAdmin(BlogPostAdmin):
+    fieldsets = blog_fieldsets
+    filter_horizontal = blog_filter_horizontal
+
+admin.site.unregister(BlogPost)
+admin.site.register(BlogPost, MyBlogPostAdmin)
+
+
 admin.site.unregister(Product)
 admin.site.register(Product, RecordProductAdmin)
 
diff --git a/diggersdigest/records/migrations/0010_auto_20150909_1400.py b/diggersdigest/records/migrations/0010_auto_20150909_1400.py
new file mode 100644 (file)
index 0000000..acad3b9
--- /dev/null
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('records', '0009_remove_record_image'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='artist',
+            options={'ordering': ['name']},
+        ),
+    ]
index 7ba2141857ef277ca26fc8eb50ae4d194aa2f2fc..42f16bd2aac8e0f65b15946f59540e0fe4ccfec5 100644 (file)
@@ -13,7 +13,7 @@ from mezzanine.core.models import CONTENT_STATUS_DRAFT, CONTENT_STATUS_PUBLISHED
 from mezzanine.blog.models import BlogPost
 from mezzanine.utils.models import upload_to
 
-from cartridge.shop.models import Product
+from cartridge.shop.models import Product, Category
 
 
 # Auto-generated Django models with manage.py inspectdb on the old database