|
|
|
@ -2,6 +2,7 @@ import json |
|
|
|
from django.core.management.base import BaseCommand |
|
|
|
from repostajes.models import Repostaje |
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand): |
|
|
|
help = "Importa repostajes desde un archivo JSON" |
|
|
|
|
|
|
|
@ -15,6 +16,13 @@ class Command(BaseCommand): |
|
|
|
with open(archivo_json, 'r', encoding='utf-8') as file: |
|
|
|
datos = json.load(file) |
|
|
|
|
|
|
|
self.stdout.write(self.style.WARNING(f"\nSe encontraron {len(datos)} repostajes en el archivo '{archivo_json}'.")) |
|
|
|
confirmar = input("¿Deseas continuar con la importación? (s/n): ").strip().lower() |
|
|
|
|
|
|
|
if confirmar != 's': |
|
|
|
self.stdout.write(self.style.ERROR("Importación cancelada.")) |
|
|
|
return |
|
|
|
|
|
|
|
repostajes_creados = 0 |
|
|
|
for repostaje_data in datos: |
|
|
|
repostaje, creado = Repostaje.objects.get_or_create( |
|
|
|
|