From 132c9e8bb31a23ed77784e4fe3ec53217ac94299 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Wed, 9 Sep 2015 18:29:32 +0200 Subject: [PATCH] Add extra field to BlogPost to handle products in news --- diggersdigest/diggersdigest/local_settings.py | 14 +--- .../migrations/blog/0001_initial.py | 69 +++++++++++++++++++ .../blog/0002_auto_20150527_1555.py | 19 +++++ .../blog/0003_blogpost_related_products.py | 20 ++++++ .../diggersdigest/migrations/blog/__init__.py | 0 diggersdigest/diggersdigest/settings.py | 48 ++++++++----- diggersdigest/records/admin.py | 24 +++++++ .../migrations/0010_auto_20150909_1400.py | 18 +++++ diggersdigest/records/models.py | 2 +- 9 files changed, 181 insertions(+), 33 deletions(-) create mode 100644 diggersdigest/diggersdigest/migrations/blog/0001_initial.py create mode 100644 diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py create mode 100644 diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py create mode 100644 diggersdigest/diggersdigest/migrations/blog/__init__.py create mode 100644 diggersdigest/records/migrations/0010_auto_20150909_1400.py diff --git a/diggersdigest/diggersdigest/local_settings.py b/diggersdigest/diggersdigest/local_settings.py index 14f5870..2c50da4 100644 --- a/diggersdigest/diggersdigest/local_settings.py +++ b/diggersdigest/diggersdigest/local_settings.py @@ -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 index 0000000..1124f8b --- /dev/null +++ b/diggersdigest/diggersdigest/migrations/blog/0001_initial.py @@ -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 index 0000000..a5cb65c --- /dev/null +++ b/diggersdigest/diggersdigest/migrations/blog/0002_auto_20150527_1555.py @@ -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 index 0000000..3ae1fc5 --- /dev/null +++ b/diggersdigest/diggersdigest/migrations/blog/0003_blogpost_related_products.py @@ -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 index 0000000..e69de29 diff --git a/diggersdigest/diggersdigest/settings.py b/diggersdigest/diggersdigest/settings.py index 3dd4ee0..c2868f8 100644 --- a/diggersdigest/diggersdigest/settings.py +++ b/diggersdigest/diggersdigest/settings.py @@ -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. # diff --git a/diggersdigest/records/admin.py b/diggersdigest/records/admin.py index 60fdfa5..f2276a7 100644 --- a/diggersdigest/records/admin.py +++ b/diggersdigest/records/admin.py @@ -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 index 0000000..acad3b9 --- /dev/null +++ b/diggersdigest/records/migrations/0010_auto_20150909_1400.py @@ -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']}, + ), + ] diff --git a/diggersdigest/records/models.py b/diggersdigest/records/models.py index 7ba2141..42f16bd 100644 --- a/diggersdigest/records/models.py +++ b/diggersdigest/records/models.py @@ -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 -- 2.39.5