-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.py
94 lines (82 loc) · 2.01 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from peewee import SqliteDatabase
from peewee import AutoField
from peewee import CharField
from peewee import DateField
from peewee import IntegerField
from peewee import Model
from datetime import datetime
from os import path
from sys import platform
sistema = platform
ruta1 = path.abspath(__file__)
ruta2 = path.split(ruta1)
# Determina en que OS estamos trabajando
if sistema == "linux":
# if not os.path.isfile(ruta2[0] + "/" + "base_datos.db"):
ruta3 = ruta2[0] + "/" + "base_datos.db"
elif sistema == "win32" or "win64":
ruta3 = ruta2[0] + "\\" + "base_datos.db"
else:
print("Sistema no reconocido")
print("OS:", sistema)
print("db:", ruta3)
# Nombre de la base de datos
db = SqliteDatabase(ruta3)
# Crear la base de datos y su tabla
class BaseDatos(Model):
orden = AutoField()
fecha = DateField()
nombre = CharField()
apellido = CharField()
telefono = CharField()
direccion = CharField()
tipo = CharField()
marca = CharField()
modelo = CharField()
falla = CharField()
otros = CharField()
estado = IntegerField() # IntegerField para numeros
costo = IntegerField()
total = IntegerField()
descripcion = CharField() # CharField para caracteres
notificacion = CharField()
class Meta:
database = db
def guardar(
self,
nomb,
apel,
tele,
dire,
tipo,
marc,
mode,
fall,
otro,
esta,
cost,
tota,
decr,
noti,
fech=datetime.now(),
):
datos = BaseDatos(
fecha=fech,
nombre=nomb,
apellido=apel,
telefono=tele,
direccion=dire,
tipo=tipo,
marca=marc,
modelo=mode,
falla=fall,
otros=otro,
estado=esta,
costo=cost,
total=tota,
descripcion=decr,
notificacion=noti,
)
datos.save()
db.connect()
db.create_tables([BaseDatos])