From 13a8c41e86092aff9a8a58820ed219658e20afec Mon Sep 17 00:00:00 2001 From: jacobtm Date: Fri, 24 Jan 2020 12:41:25 +0000 Subject: [PATCH 1/3] Change to use default custom image model --- bakerydemo/base/fixtures/bakerydemo.json | 74 +++++++++---------- .../0005_change_to_media_image_model.py | 44 +++++++++++ bakerydemo/base/models.py | 12 +-- bakerydemo/base/templatetags/gallery_tags.py | 4 +- .../0004_change_to_media_image_model.py | 24 ++++++ bakerydemo/blog/models.py | 4 +- .../0004_change_to_media_image_model.py | 24 ++++++ bakerydemo/breads/models.py | 4 +- .../0005_change_to_media_image_model.py | 24 ++++++ bakerydemo/locations/models.py | 4 +- bakerydemo/settings/base.py | 4 + 11 files changed, 171 insertions(+), 51 deletions(-) create mode 100644 bakerydemo/base/migrations/0005_change_to_media_image_model.py create mode 100644 bakerydemo/blog/migrations/0004_change_to_media_image_model.py create mode 100644 bakerydemo/breads/migrations/0004_change_to_media_image_model.py create mode 100644 bakerydemo/locations/migrations/0005_change_to_media_image_model.py diff --git a/bakerydemo/base/fixtures/bakerydemo.json b/bakerydemo/base/fixtures/bakerydemo.json index d6598821c..9a50e91e0 100644 --- a/bakerydemo/base/fixtures/bakerydemo.json +++ b/bakerydemo/base/fixtures/bakerydemo.json @@ -2424,7 +2424,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 8, "fields": { "collection": 3, @@ -2444,7 +2444,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 9, "fields": { "collection": 2, @@ -2464,7 +2464,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 10, "fields": { "collection": 2, @@ -2484,7 +2484,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 11, "fields": { "collection": 2, @@ -2504,7 +2504,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 12, "fields": { "collection": 2, @@ -2524,7 +2524,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 14, "fields": { "collection": 2, @@ -2544,7 +2544,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 15, "fields": { "collection": 2, @@ -2564,7 +2564,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 21, "fields": { "collection": 2, @@ -2584,7 +2584,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 22, "fields": { "collection": 2, @@ -2604,7 +2604,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 23, "fields": { "collection": 2, @@ -2624,7 +2624,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 24, "fields": { "collection": 2, @@ -2644,7 +2644,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 25, "fields": { "collection": 2, @@ -2664,7 +2664,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 26, "fields": { "collection": 4, @@ -2684,7 +2684,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 28, "fields": { "collection": 4, @@ -2704,7 +2704,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 29, "fields": { "collection": 4, @@ -2724,7 +2724,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 30, "fields": { "collection": 4, @@ -2744,7 +2744,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 31, "fields": { "collection": 4, @@ -2764,7 +2764,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 32, "fields": { "collection": 4, @@ -2784,7 +2784,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 33, "fields": { "collection": 4, @@ -2804,7 +2804,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 34, "fields": { "collection": 4, @@ -2824,7 +2824,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 35, "fields": { "collection": 4, @@ -2844,7 +2844,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 36, "fields": { "collection": 4, @@ -2864,7 +2864,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 37, "fields": { "collection": 4, @@ -2884,7 +2884,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 39, "fields": { "collection": 4, @@ -2904,7 +2904,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 40, "fields": { "collection": 4, @@ -2924,7 +2924,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 41, "fields": { "collection": 3, @@ -2944,7 +2944,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 42, "fields": { "collection": 3, @@ -2964,7 +2964,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 43, "fields": { "collection": 3, @@ -2984,7 +2984,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 44, "fields": { "collection": 1, @@ -3004,7 +3004,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 45, "fields": { "collection": 1, @@ -3024,7 +3024,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 46, "fields": { "collection": 1, @@ -3044,7 +3044,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 47, "fields": { "collection": 1, @@ -3064,7 +3064,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 48, "fields": { "collection": 1, @@ -3084,7 +3084,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 49, "fields": { "collection": 1, @@ -3104,7 +3104,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 51, "fields": { "collection": 3, @@ -3124,7 +3124,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 52, "fields": { "collection": 3, @@ -3144,7 +3144,7 @@ } }, { - "model": "wagtailimages.image", + "model": "media.image", "pk": 53, "fields": { "collection": 3, diff --git a/bakerydemo/base/migrations/0005_change_to_media_image_model.py b/bakerydemo/base/migrations/0005_change_to_media_image_model.py new file mode 100644 index 000000000..6a74444c4 --- /dev/null +++ b/bakerydemo/base/migrations/0005_change_to_media_image_model.py @@ -0,0 +1,44 @@ +# Generated by Django 2.2.9 on 2020-01-23 15:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0004_auto_20180522_1856'), + ] + + operations = [ + migrations.AlterField( + model_name='formpage', + name='image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='gallerypage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='homepage', + name='image', + field=models.ForeignKey(blank=True, help_text='Homepage image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='homepage', + name='promo_image', + field=models.ForeignKey(blank=True, help_text='Promo image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='people', + name='image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='standardpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + ] diff --git a/bakerydemo/base/models.py b/bakerydemo/base/models.py index 813ded7a1..c15503d1a 100644 --- a/bakerydemo/base/models.py +++ b/bakerydemo/base/models.py @@ -42,7 +42,7 @@ class People(index.Indexed, ClusterableModel): job_title = models.CharField("Job title", max_length=254) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -114,7 +114,7 @@ class StandardPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -144,7 +144,7 @@ class HomePage(Page): # Hero section of HomePage image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -177,7 +177,7 @@ class HomePage(Page): # Promo section of the HomePage promo_image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -299,7 +299,7 @@ class GalleryPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -345,7 +345,7 @@ class FormField(AbstractFormField): class FormPage(AbstractEmailForm): image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, diff --git a/bakerydemo/base/templatetags/gallery_tags.py b/bakerydemo/base/templatetags/gallery_tags.py index 488c7a8b0..5b0fda3e9 100644 --- a/bakerydemo/base/templatetags/gallery_tags.py +++ b/bakerydemo/base/templatetags/gallery_tags.py @@ -1,6 +1,6 @@ from django import template -from wagtail.images.models import Image +from wagtail.images import get_image_model register = template.Library() @@ -8,7 +8,7 @@ # Retrieves a single gallery item and returns a gallery of images @register.inclusion_tag('tags/gallery.html', takes_context=True) def gallery(context, gallery): - images = Image.objects.filter(collection=gallery) + images = get_image_model().objects.filter(collection=gallery) return { 'images': images, diff --git a/bakerydemo/blog/migrations/0004_change_to_media_image_model.py b/bakerydemo/blog/migrations/0004_change_to_media_image_model.py new file mode 100644 index 000000000..4017ec2c0 --- /dev/null +++ b/bakerydemo/blog/migrations/0004_change_to_media_image_model.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.9 on 2020-01-23 15:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0003_auto_20170329_0055'), + ] + + operations = [ + migrations.AlterField( + model_name='blogindexpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='blogpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + ] diff --git a/bakerydemo/blog/models.py b/bakerydemo/blog/models.py index 0f4f4fcc1..230d295c8 100644 --- a/bakerydemo/blog/models.py +++ b/bakerydemo/blog/models.py @@ -60,7 +60,7 @@ class BlogPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -143,7 +143,7 @@ class BlogIndexPage(RoutablePageMixin, Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, diff --git a/bakerydemo/breads/migrations/0004_change_to_media_image_model.py b/bakerydemo/breads/migrations/0004_change_to_media_image_model.py new file mode 100644 index 000000000..74c08fccf --- /dev/null +++ b/bakerydemo/breads/migrations/0004_change_to_media_image_model.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.9 on 2020-01-23 15:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('breads', '0003_auto_20170329_0055'), + ] + + operations = [ + migrations.AlterField( + model_name='breadpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='breadsindexpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + ] diff --git a/bakerydemo/breads/models.py b/bakerydemo/breads/models.py index 332f812f8..5309b6a45 100644 --- a/bakerydemo/breads/models.py +++ b/bakerydemo/breads/models.py @@ -91,7 +91,7 @@ class BreadPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -160,7 +160,7 @@ class BreadsIndexPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, diff --git a/bakerydemo/locations/migrations/0005_change_to_media_image_model.py b/bakerydemo/locations/migrations/0005_change_to_media_image_model.py new file mode 100644 index 000000000..e6ae682c9 --- /dev/null +++ b/bakerydemo/locations/migrations/0005_change_to_media_image_model.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.9 on 2020-01-23 15:23 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('locations', '0004_auto_20190912_1149'), + ] + + operations = [ + migrations.AlterField( + model_name='locationpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + migrations.AlterField( + model_name='locationsindexpage', + name='image', + field=models.ForeignKey(blank=True, help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='media.Image'), + ), + ] diff --git a/bakerydemo/locations/models.py b/bakerydemo/locations/models.py index 3156c1173..df3387fcb 100644 --- a/bakerydemo/locations/models.py +++ b/bakerydemo/locations/models.py @@ -91,7 +91,7 @@ class LocationsIndexPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, @@ -132,7 +132,7 @@ class LocationPage(Page): help_text='Text to describe the page', blank=True) image = models.ForeignKey( - 'wagtailimages.Image', + 'media.Image', null=True, blank=True, on_delete=models.SET_NULL, diff --git a/bakerydemo/settings/base.py b/bakerydemo/settings/base.py index ceb95734f..fc27123df 100644 --- a/bakerydemo/settings/base.py +++ b/bakerydemo/settings/base.py @@ -31,6 +31,7 @@ # Application definition INSTALLED_APPS = [ + 'media', 'bakerydemo.base', 'bakerydemo.blog', 'bakerydemo.breads', @@ -177,3 +178,6 @@ # Wagtail settings WAGTAIL_SITE_NAME = "bakerydemo" + +WAGTAILDOCS_DOCUMENT_MODEL = 'media.Document' +WAGTAILIMAGES_IMAGE_MODEL = 'media.Image' From 34e6e874787e790943e55dce7461991c8ef811b4 Mon Sep 17 00:00:00 2001 From: jacobtm Date: Fri, 24 Jan 2020 15:28:31 +0000 Subject: [PATCH 2/3] Add media app with custom image model, and migrations --- .../0005_change_to_media_image_model.py | 2 +- .../0004_change_to_media_image_model.py | 2 +- .../0004_change_to_media_image_model.py | 2 +- .../0005_change_to_media_image_model.py | 2 +- media/__init__.py | 0 media/migrations/0001_initial.py | 83 +++++++++++++++++++ media/migrations/__init__.py | 0 media/models.py | 45 ++++++++++ 8 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 media/__init__.py create mode 100644 media/migrations/0001_initial.py create mode 100644 media/migrations/__init__.py create mode 100644 media/models.py diff --git a/bakerydemo/base/migrations/0005_change_to_media_image_model.py b/bakerydemo/base/migrations/0005_change_to_media_image_model.py index 6a74444c4..b38499a1c 100644 --- a/bakerydemo/base/migrations/0005_change_to_media_image_model.py +++ b/bakerydemo/base/migrations/0005_change_to_media_image_model.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.9 on 2020-01-23 15:23 +# Generated by Django 2.2.9 on 2020-01-24 15:09 from django.db import migrations, models import django.db.models.deletion diff --git a/bakerydemo/blog/migrations/0004_change_to_media_image_model.py b/bakerydemo/blog/migrations/0004_change_to_media_image_model.py index 4017ec2c0..84c81a39b 100644 --- a/bakerydemo/blog/migrations/0004_change_to_media_image_model.py +++ b/bakerydemo/blog/migrations/0004_change_to_media_image_model.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.9 on 2020-01-23 15:23 +# Generated by Django 2.2.9 on 2020-01-24 15:09 from django.db import migrations, models import django.db.models.deletion diff --git a/bakerydemo/breads/migrations/0004_change_to_media_image_model.py b/bakerydemo/breads/migrations/0004_change_to_media_image_model.py index 74c08fccf..766945634 100644 --- a/bakerydemo/breads/migrations/0004_change_to_media_image_model.py +++ b/bakerydemo/breads/migrations/0004_change_to_media_image_model.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.9 on 2020-01-23 15:23 +# Generated by Django 2.2.9 on 2020-01-24 15:09 from django.db import migrations, models import django.db.models.deletion diff --git a/bakerydemo/locations/migrations/0005_change_to_media_image_model.py b/bakerydemo/locations/migrations/0005_change_to_media_image_model.py index e6ae682c9..7112998c8 100644 --- a/bakerydemo/locations/migrations/0005_change_to_media_image_model.py +++ b/bakerydemo/locations/migrations/0005_change_to_media_image_model.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.9 on 2020-01-23 15:23 +# Generated by Django 2.2.9 on 2020-01-24 15:09 from django.db import migrations, models import django.db.models.deletion diff --git a/media/__init__.py b/media/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/media/migrations/0001_initial.py b/media/migrations/0001_initial.py new file mode 100644 index 000000000..1976c93e5 --- /dev/null +++ b/media/migrations/0001_initial.py @@ -0,0 +1,83 @@ +# Generated by Django 2.2.9 on 2020-01-24 15:08 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import taggit.managers +import wagtail.core.models +import wagtail.images.models +import wagtail.search.index + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('taggit', '0003_taggeditem_add_unique_index'), + ('wagtailcore', '0045_assign_unlock_grouppagepermission'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Image', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255, verbose_name='title')), + ('file', models.ImageField(height_field='height', upload_to=wagtail.images.models.get_upload_to, verbose_name='file', width_field='width')), + ('width', models.IntegerField(editable=False, verbose_name='width')), + ('height', models.IntegerField(editable=False, verbose_name='height')), + ('created_at', models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='created at')), + ('focal_point_x', models.PositiveIntegerField(blank=True, null=True)), + ('focal_point_y', models.PositiveIntegerField(blank=True, null=True)), + ('focal_point_width', models.PositiveIntegerField(blank=True, null=True)), + ('focal_point_height', models.PositiveIntegerField(blank=True, null=True)), + ('file_size', models.PositiveIntegerField(editable=False, null=True)), + ('file_hash', models.CharField(blank=True, editable=False, max_length=40)), + ('collection', models.ForeignKey(default=wagtail.core.models.get_root_collection_id, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailcore.Collection', verbose_name='collection')), + ('tags', taggit.managers.TaggableManager(blank=True, help_text=None, related_name='images', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='tags')), + ('uploaded_by_user', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='uploaded by user')), + ], + options={ + 'verbose_name': 'image', + 'verbose_name_plural': 'images', + }, + bases=(wagtail.search.index.Indexed, models.Model), + ), + migrations.CreateModel( + name='Document', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=255, verbose_name='title')), + ('file', models.FileField(upload_to='documents', verbose_name='file')), + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')), + ('file_size', models.PositiveIntegerField(editable=False, null=True)), + ('file_hash', models.CharField(blank=True, editable=False, max_length=40)), + ('collection', models.ForeignKey(default=wagtail.core.models.get_root_collection_id, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailcore.Collection', verbose_name='collection')), + ('tags', taggit.managers.TaggableManager(blank=True, help_text=None, related_name='documents', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='tags')), + ('uploaded_by_user', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='uploaded by user')), + ], + options={ + 'verbose_name': 'document', + 'verbose_name_plural': 'documents', + 'abstract': False, + }, + bases=(wagtail.search.index.Indexed, models.Model), + ), + migrations.CreateModel( + name='Rendition', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('filter_spec', models.CharField(db_index=True, max_length=255)), + ('file', models.ImageField(height_field='height', upload_to=wagtail.images.models.get_rendition_upload_to, width_field='width')), + ('width', models.IntegerField(editable=False)), + ('height', models.IntegerField(editable=False)), + ('focal_point_key', models.CharField(blank=True, default='', editable=False, max_length=16)), + ('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='renditions', to='media.Image')), + ], + options={ + 'unique_together': {('image', 'filter_spec', 'focal_point_key')}, + }, + ), + ] diff --git a/media/migrations/__init__.py b/media/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/media/models.py b/media/models.py new file mode 100644 index 000000000..159e0c985 --- /dev/null +++ b/media/models.py @@ -0,0 +1,45 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from wagtail.documents.models import AbstractDocument +from wagtail.images.models import AbstractImage, AbstractRendition + +from taggit.managers import TaggableManager + + +class Image(AbstractImage): + admin_form_fields = ( + 'title', + 'file', + 'collection', + 'tags', + 'focal_point_x', + 'focal_point_y', + 'focal_point_width', + 'focal_point_height', + ) + + tags = TaggableManager(help_text=None, blank=True, verbose_name=_('tags'), related_name='images') + + class Meta: + verbose_name = _('image') + verbose_name_plural = _('images') + + +class Rendition(AbstractRendition): + image = models.ForeignKey(Image, related_name='renditions', on_delete=models.CASCADE) + + class Meta: + unique_together = ( + ('image', 'filter_spec', 'focal_point_key'), + ) + + +class Document(AbstractDocument): + admin_form_fields = ( + 'title', + 'file', + 'collection', + 'tags' + ) + + tags = TaggableManager(help_text=None, blank=True, verbose_name=_('tags'), related_name='documents') From 0823bddaf612bcba2c0f4f6478ea140959aff698 Mon Sep 17 00:00:00 2001 From: jacobtm Date: Fri, 24 Jan 2020 15:47:57 +0000 Subject: [PATCH 3/3] Add default alt text --- .../migrations/0002_image_generic_alt_text.py | 18 ++++++++++++++++++ media/models.py | 13 +++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 media/migrations/0002_image_generic_alt_text.py diff --git a/media/migrations/0002_image_generic_alt_text.py b/media/migrations/0002_image_generic_alt_text.py new file mode 100644 index 000000000..3966bc62b --- /dev/null +++ b/media/migrations/0002_image_generic_alt_text.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.9 on 2020-01-24 15:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('media', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='image', + name='generic_alt_text', + field=models.CharField(blank=True, max_length=600, verbose_name='default alt text'), + ), + ] diff --git a/media/models.py b/media/models.py index 159e0c985..c2ef897d6 100644 --- a/media/models.py +++ b/media/models.py @@ -12,6 +12,7 @@ class Image(AbstractImage): 'file', 'collection', 'tags', + 'default_alt_text' 'focal_point_x', 'focal_point_y', 'focal_point_width', @@ -19,6 +20,14 @@ class Image(AbstractImage): ) tags = TaggableManager(help_text=None, blank=True, verbose_name=_('tags'), related_name='images') + generic_alt_text = models.CharField(max_length=600, verbose_name=_('default alt text'), blank=True) + + @property + def default_alt_text(self): + if self.generic_alt_text: + return self.generic_alt_text + else: + return super().default_alt_text class Meta: verbose_name = _('image') @@ -28,6 +37,10 @@ class Meta: class Rendition(AbstractRendition): image = models.ForeignKey(Image, related_name='renditions', on_delete=models.CASCADE) + @property + def alt(self): + return self.image.default_alt_text + class Meta: unique_together = ( ('image', 'filter_spec', 'focal_point_key'),