Created
February 22, 2021 20:22
-
-
Save danliberato/a68b5dcaad59b5e53efd79d66536a965 to your computer and use it in GitHub Desktop.
Save EmbeddedDocument example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from src.models.invoice_model import InvoiceModel | |
from src.models.payment_info_model import PaymentInfoModel | |
from src.services.mongo_service import MongoService | |
### find invoice by taxId | |
inv = InvoiceModel.objects().get(tx_id='0d5bda0568df40c49066e570df86e511') | |
### There are two ways to update an EmbeddedDocumnet | |
### 1) change the fields without an auxiliary PaymentInfoModel | |
inv.payment_info.tx_id = "tx_id_example_1" | |
inv.payment_info.amount = 13.91 | |
inv.payment_info.time = datetime.now() | |
inv.save() | |
print('BREAKPOINT HERE, check document on DB.') | |
### 2) Instanciate a new PaymentInfoModel and put it into the InvoiceModel: | |
payment_info = PaymentInfoModel() | |
payment_info.tx_id = "tx_id_example_2" | |
payment_info.amount = 13.91 | |
payment_info.horario = datetime.now() | |
inv.pix_payment_info = payment_info | |
inv.save() | |
print('COLOCAR BREAKPOINT AQUI, checar no banco!')print('BREAKPOINT HERE, check document on DB.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment