forked from ChristopherAndreyPiske/primeiro-projeto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimais.py
101 lines (68 loc) · 2.26 KB
/
animais.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
95
96
97
98
99
100
101
import os
from peewee import *
db = SqliteDatabase('animalia.db')
class Animal (Model):
nomedono =CharField()
tipo_animal =CharField()
raca =CharField()
class Meta:
database = db
def __str__(self):
return self.tipo_animal+","+self.raca+" de "+self.nomedono
class Cliente (Model):
nome =CharField()
email =CharField()
telefone =CharField()
nome_login =CharField()
senha =CharField()
class Meta:
database = db
def __str__(self):
return self.nome+", "+self.email+" - "+self.telefone+\
" | "+self.nome_login+"/"+self.senha
class Consulta (Model):
data =CharField()
servico =CharField()
horario =CharField()
animal =ForeignKeyField(Animal)
cliente =ForeignKeyField(Cliente)
confirma =CharField()
myID =CharField()
class Meta:
database = db
def __str__(self):
return self.servico+" em "+self.data+":"+self.horario+", confirmado: "+\
self.confirma+", ID da consulta: "+self.myID+\
" | animal: "+str(self.animal)+" | cliente: "+str(self.cliente)
if __name__ == '__main__':
arq = 'animalia.db'
if os.path.exists(arq):
os.remove(arq)
try:
db.connect()
db.create_tables([Animal,Consulta,Cliente])
except OperationalError as e:
print("erro ao criar tabelas: "+str(e))
print("TESTE DO ANIMAL")
a1 = Animal(nomedono="José", tipo_animal="C", raca="Chiuaua")
print(a1)
print("TESTE DO CLIENTE")
jose = Cliente(nome="José", email="[email protected]", telefone="47 99200-1010",
nome_login="josesoueu", senha="123deoliveira4")
print(jose)
print("TESTE DA CONSULTA")
c1 = Consulta(data="19/09/2018", servico="Consulta de rotina",
horario="14:00", animal=a1, cliente=jose, confirma="N",
myID="c9d8f7gu4h3hnwsik3e")
print(c1)
print("TESTE DA PERSISTÊNCIA")
a1.save()
jose.save()
c1.save()
c2 = Consulta(data="21/09/2018", servico="Aplicação de vacina",
horario="10:00", animal=a1, cliente=jose,
confirma="S", myID="d9firtu3434uit")
c2.save()
todos = Consulta.select()
for con in todos:
print(con)