Files
Fil-A-Management/filament/management/commands/seed_catalog.py
T

41 lines
1.5 KiB
Python

from decimal import Decimal
from django.core.management.base import BaseCommand
from django.db import transaction
from filament.models import Color, Manufacturer, ProductType, Variant
class Command(BaseCommand):
help = "Ergänzt acht PLA-Matte-Beispielvarianten; überschreibt keine bestehenden Daten."
@transaction.atomic
def handle(self, *args, **options):
manufacturer, _ = Manufacturer.objects.get_or_create(name="Bambu Lab")
product, _ = ProductType.objects.get_or_create(manufacturer=manufacturer, name="PLA Matte")
created = 0
# Source: https://eu.store.bambulab.com/products/pla-matte (see README).
for name, code in [
("Elfenbeinweiß", "11100"),
("Kohleschwarz", "11101"),
("Scharlachrot", "11200"),
("Eisblau", "11601"),
]:
color, _ = Color.objects.get_or_create(name=name)
for spool_type in Variant.SpoolType.values:
_, new = Variant.objects.get_or_create(
product_type=product,
color=color,
spool_type=spool_type,
defaults={
"manufacturer_color_code": code,
"net_weight_g": 1000,
"diameter_mm": Decimal("1.75"),
},
)
created += new
if options["verbosity"]:
self.stdout.write(
self.style.SUCCESS(f"Beispielkatalog bereit: {created} Varianten ergänzt.")
)