Add custom image model
This commit is contained in:
parent
b8edb525dc
commit
c23c03ec33
8 changed files with 266 additions and 0 deletions
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-28 17:52
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("images", "__first__"),
|
||||
("blog", "0006_alter_bloglistpage_body_alter_blogpostpage_body"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="bloglistpage",
|
||||
name="hero_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="images.customimage",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="blogpostpage",
|
||||
name="hero_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="images.customimage",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-28 17:52
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("images", "__first__"),
|
||||
("common", "0007_alter_contentpage_body_alter_listingpage_body"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="contentpage",
|
||||
name="hero_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="images.customimage",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="listingpage",
|
||||
name="hero_image",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="images.customimage",
|
||||
),
|
||||
),
|
||||
]
|
24
website/home/migrations/0005_alter_homepage_image.py
Normal file
24
website/home/migrations/0005_alter_homepage_image.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-28 17:52
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("images", "__first__"),
|
||||
("home", "0004_homepage_image"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="homepage",
|
||||
name="image",
|
||||
field=models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="images.customimage",
|
||||
),
|
||||
),
|
||||
]
|
0
website/images/__init__.py
Normal file
0
website/images/__init__.py
Normal file
154
website/images/migrations/0001_initial.py
Normal file
154
website/images/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,154 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-28 17:52
|
||||
|
||||
import django.db.models.deletion
|
||||
import taggit.managers
|
||||
import wagtail.images.models
|
||||
import wagtail.models.collections
|
||||
import wagtail.search.index
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("taggit", "0004_alter_taggeditem_content_type_alter_taggeditem_tag"),
|
||||
("wagtailcore", "0069_log_entry_jsonfield"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="CustomImage",
|
||||
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, db_index=True, editable=False, max_length=40
|
||||
),
|
||||
),
|
||||
(
|
||||
"collection",
|
||||
models.ForeignKey(
|
||||
default=wagtail.models.collections.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,
|
||||
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,
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
verbose_name="uploaded by user",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
bases=(
|
||||
wagtail.images.models.ImageFileMixin,
|
||||
wagtail.search.index.Indexed,
|
||||
models.Model,
|
||||
),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="CustomRendition",
|
||||
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="images.customimage",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"unique_together": {("image", "filter_spec", "focal_point_key")},
|
||||
},
|
||||
bases=(wagtail.images.models.ImageFileMixin, models.Model),
|
||||
),
|
||||
]
|
0
website/images/migrations/__init__.py
Normal file
0
website/images/migrations/__init__.py
Normal file
15
website/images/models.py
Normal file
15
website/images/models.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django.db import models
|
||||
from wagtail.images.models import AbstractImage, AbstractRendition
|
||||
|
||||
|
||||
class CustomImage(AbstractImage):
|
||||
pass
|
||||
|
||||
|
||||
class CustomRendition(AbstractRendition):
|
||||
image = models.ForeignKey(
|
||||
CustomImage, on_delete=models.CASCADE, related_name="renditions"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = (("image", "filter_spec", "focal_point_key"),)
|
|
@ -23,6 +23,7 @@ INSTALLED_APPS = [
|
|||
"website.home",
|
||||
"website.search",
|
||||
"website.blog",
|
||||
"website.images",
|
||||
"website.contrib.code_block",
|
||||
"wagtail.contrib.forms",
|
||||
"wagtail.contrib.redirects",
|
||||
|
@ -141,6 +142,8 @@ WAGTAILADMIN_BASE_URL = f"https://{BASE_HOSTNAME}"
|
|||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
|
||||
WAGTAILIMAGES_IMAGE_MODEL = "images.CustomImage"
|
||||
|
||||
if DEBUG:
|
||||
# Add django-browser-reload
|
||||
INSTALLED_APPS.append("django_browser_reload")
|
||||
|
|
Loading…
Reference in a new issue