51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# Generated by Django 5.2.19 on 2026-11-14 13:53
|
|
|
|
import django.core.validators
|
|
from django.db import migrations, models
|
|
|
|
from filament.bambu_images_0006 import bambu_image_url
|
|
|
|
|
|
def fill_bambu_images(apps, schema_editor):
|
|
variant_model = apps.get_model("filament", "Variant")
|
|
variants = variant_model.objects.using(schema_editor.connection.alias).filter(
|
|
product_type__manufacturer__name="Bambu Lab", image_url=""
|
|
)
|
|
updates = []
|
|
for variant in variants.select_related("product_type", "color"):
|
|
image = bambu_image_url(
|
|
variant.product_type.name,
|
|
variant.manufacturer_color_code or variant.color.name,
|
|
variant.spool_type,
|
|
)
|
|
if image:
|
|
variant.image_url = image
|
|
updates.append(variant)
|
|
variants.bulk_update(updates, ["image_url"])
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("filament", "0005_variant_swatch"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name="variant",
|
|
name="image_url",
|
|
field=models.URLField(
|
|
blank=True,
|
|
help_text="Bildadresse von cdn.shopify.com, store.bblcdn.eu oder store.bblcdn.com.",
|
|
max_length=500,
|
|
validators=[
|
|
django.core.validators.RegexValidator(
|
|
"\\Ahttps://(?:cdn\\.shopify\\.com|store\\.bblcdn\\.eu|store\\.bblcdn\\.com)/",
|
|
"Bitte eine HTTPS-Bildadresse von einer unterstützten CDN-Domain eingeben.",
|
|
)
|
|
],
|
|
verbose_name="Produktbild",
|
|
),
|
|
),
|
|
migrations.RunPython(fill_bambu_images, migrations.RunPython.noop),
|
|
]
|