Browse Source

Pido confirmación para insertar json

politica
Celestino Rey 10 months ago
parent
commit
f29c2a7e09
3 changed files with 46 additions and 0 deletions
  1. +31
    -0
      ReyMotaAppsDj/K8S/reymota-ingress.yaml
  2. +8
    -0
      ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py
  3. +7
    -0
      ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py

+ 31
- 0
ReyMotaAppsDj/K8S/reymota-ingress.yaml View File

@ -0,0 +1,31 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
generation: 1
managedFields:
- apiVersion: networking.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:defaultBackend:
.: {}
f:service:
.: {}
f:name: {}
f:port: {}
f:rules: {}
manager: rancher
operation: Update
name: reymota
namespace: reymota
spec:
defaultBackend:
service:
name: nginx
port:
number: 1337
ingressClassName: nginx
rules:
- host: reymota.rancher.my.org
status:
loadBalancer: {}

+ 8
- 0
ReyMotaAppsDj/reymota/repostajes/management/commands/importar_repostajes.py View File

@ -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(


+ 7
- 0
ReyMotaAppsDj/reymota/repostajes/management/commands/importar_vehiculos.py View File

@ -16,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)} vehiculos 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
vehiculos_creados = 0
for vehiculo_data in datos:
vehiculo, creado = Vehiculo.objects.get_or_create(


Loading…
Cancel
Save