From 16e824cc3aea84ef526010285d300a7e36d88931 Mon Sep 17 00:00:00 2001 From: Andrey Shpak Date: Wed, 17 Aug 2022 10:45:56 +0300 Subject: [PATCH] Simplify data deletion in example app --- example_app/views.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/example_app/views.py b/example_app/views.py index 5bc04375..63a83133 100644 --- a/example_app/views.py +++ b/example_app/views.py @@ -4,12 +4,6 @@ from mongoengine.context_managers import switch_db from example_app import models -from example_app.binary_demo import BinaryDemoModel -from example_app.boolean_demo import BooleanDemoModel -from example_app.dates_demo import DateTimeModel -from example_app.dict_demo import DictDemoModel -from example_app.numbers_demo import NumbersDemoModel -from example_app.strings_demo import StringsDemoModel def generate_data(): @@ -51,16 +45,11 @@ def generate_data(): def delete_data(): """Clear database.""" - with switch_db(models.Todo, "default"): - models.Todo.objects().delete() - BooleanDemoModel.objects().delete() - DateTimeModel.objects().delete() - DictDemoModel.objects().delete() - StringsDemoModel.objects().delete() - NumbersDemoModel.objects().delete() - BinaryDemoModel.objects().delete() - with switch_db(models.Todo, "secondary"): - models.Todo.objects().delete() + from example_app.app import db + + connection = db.connection + connection["default"].drop_database("example_app") + connection["secondary"].drop_database("example_app_2") def index():