-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.py
73 lines (52 loc) · 1.89 KB
/
Model.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
from pymongo.mongo_client import MongoClient
from pymongo import *
class Model():
def __init__(self):
self.client = MongoClient("mongodb+srv://isabelly:[email protected]/?retryWrites=true&w=majority")
self.db = self.client["Cavv_db"]
self.collection = self.db["cadastro"]
self.id = ""
self.titulo = ""
self.diretor = ""
self.review = ""
self.status = ""
self.genero = ""
self.nota = ""
def salvar(self):
user_data = {
'_id' : self.id,
'titulo': self.titulo,
'diretor': self.diretor,
'review': self.review,
'status': self.status,
'genero': self.genero,
'nota': self.nota
}
result_save = self.collection.insert_one(user_data)
if result_save.inserted_id:
print("Cadastro feito com sucesso!")
else:
print("Cadastro não realizado.")
def deletar(self, item_id):
result = self.collection.delete_one({"_id": item_id})
if result.deleted_count > 0:
print("Item deletado com sucesso!")
else:
print("Nenhum item foi deletado.")
def atualizar(self, item_id, titulo, diretor, review, genero, nota):
result = self.collection.update_one(
{"_id": item_id},
{
"$set": {
"titulo": titulo,
"diretor": diretor,
"review": review,
"genero": genero,
"nota": nota
}
}
)
if result.modified_count > 0:
print("Item atualizado com sucesso!")
else:
print("Nenhum item foi atualizado.")