website/hub/services/migrations/0040_add_image_library.py
Tobias Brunner 52dbe89582
image library
created using VS Codey Copilot Agent with Claude Sonnet 4
2025-07-04 16:28:13 +02:00

144 lines
4.9 KiB
Python

# Generated by Django 5.2 on 2025-07-04 14:19
import django.db.models.deletion
import hub.services.models.base
import hub.services.models.images
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("services", "0039_article_article_date"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="ImageLibrary",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"name",
models.CharField(
help_text="Descriptive name for the image", max_length=200
),
),
(
"slug",
models.SlugField(
help_text="URL-friendly version of the name",
max_length=250,
unique=True,
),
),
(
"description",
models.TextField(
blank=True, help_text="Optional description of the image"
),
),
(
"alt_text",
models.CharField(
help_text="Alternative text for accessibility", max_length=255
),
),
(
"image",
models.ImageField(
help_text="Upload image file (max 1MB)",
upload_to=hub.services.models.images.get_image_upload_path,
validators=[hub.services.models.base.validate_image_size],
),
),
(
"width",
models.PositiveIntegerField(
blank=True, help_text="Image width in pixels", null=True
),
),
(
"height",
models.PositiveIntegerField(
blank=True, help_text="Image height in pixels", null=True
),
),
(
"file_size",
models.PositiveIntegerField(
blank=True, help_text="File size in bytes", null=True
),
),
(
"category",
models.CharField(
choices=[
("logo", "Logo"),
("article", "Article Image"),
("banner", "Banner"),
("icon", "Icon"),
("screenshot", "Screenshot"),
("photo", "Photo"),
("other", "Other"),
],
default="other",
help_text="Category of the image",
max_length=20,
),
),
(
"tags",
models.CharField(
blank=True,
help_text="Comma-separated tags for searching",
max_length=500,
),
),
(
"uploaded_at",
models.DateTimeField(
auto_now_add=True,
help_text="Date and time when image was uploaded",
),
),
(
"updated_at",
models.DateTimeField(
auto_now=True,
help_text="Date and time when image was last updated",
),
),
(
"usage_count",
models.PositiveIntegerField(
default=0, help_text="Number of times this image is referenced"
),
),
(
"uploaded_by",
models.ForeignKey(
blank=True,
help_text="User who uploaded the image",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "Image",
"verbose_name_plural": "Image Library",
"ordering": ["-uploaded_at"],
},
),
]