23 lines
801 B
Python
23 lines
801 B
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from django.core.files import File
|
|
import glob
|
|
import os
|
|
import logging
|
|
from object.models import Element3D, Scene3D
|
|
logger = logging.getLogger("root")
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
root_directory = "object/management/commands/data"
|
|
|
|
files = glob.glob("*.glb", recursive=True, root_dir=root_directory)
|
|
hv = Scene3D.objects.get(id=48)
|
|
for f in files:
|
|
with open(os.path.join(root_directory, f), 'rb') as file:
|
|
el = Element3D(name=f)
|
|
el.model_file = File(file, f)
|
|
el.save()
|
|
logger.info(el)
|
|
hv.elements.add(el)
|
|
logger.info(hv.elements.count())
|
|
|