refactor codigo

This commit is contained in:
juanjo
2026-04-11 13:00:25 +02:00
parent 9e1c176ff9
commit c5f1b4e131
8 changed files with 144 additions and 16 deletions

32
init_db.py Normal file
View File

@@ -0,0 +1,32 @@
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
import django
django.setup()
from django.db import connection
with connection.cursor() as cursor:
cursor.execute("""
CREATE TABLE IF NOT EXISTS promociones (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nombre VARCHAR(255),
fecha_inicio DATE,
descripcion TEXT,
activo BOOLEAN DEFAULT 1,
categoria_id INTEGER
)
""")
cursor.execute("""
INSERT OR IGNORE INTO promociones (id, nombre, fecha_inicio, descripcion, activo, categoria_id)
VALUES (1, 'Promo Test', '2026-04-11', 'Descripcion de prueba', 1, 1)
""")
cursor.execute("""
CREATE TABLE IF NOT EXISTS categorias (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nombre VARCHAR(255)
)
""")
cursor.execute("""
INSERT OR IGNORE INTO categorias (id, nombre)
VALUES (1, 'Categoria Test')
""")
connection.commit()
print('Tablas y datos de prueba creados exitosamente en db.sqlite3')