From 7f89af129f31e5973ad578b3bcf074c5c305c919 Mon Sep 17 00:00:00 2001 From: "Pavel Turinsky (DebianVM @ Zr)" Date: Wed, 30 Jun 2021 00:59:02 +0000 Subject: [PATCH] m0060: likvidace sirotku ve stromu --- db_compare.py | 4 ++-- mamweb/settings_local.py | 14 +++++++------- seminar/migrations/0060_spoj_stromy.py | 12 ++++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/db_compare.py b/db_compare.py index 3cdee268..f960492a 100755 --- a/db_compare.py +++ b/db_compare.py @@ -3,8 +3,8 @@ import psycopg2 import psycopg2.extras -OLD_DB = "mam_old" -NEW_DB = "mamweb" +OLD_DB = "mam-prod" +NEW_DB = "mam-test" oldconn = psycopg2.connect(f"dbname={OLD_DB}") newconn = psycopg2.connect(f"dbname={NEW_DB}") diff --git a/mamweb/settings_local.py b/mamweb/settings_local.py index 0aadd27e..2ba43478 100644 --- a/mamweb/settings_local.py +++ b/mamweb/settings_local.py @@ -39,13 +39,13 @@ DATABASES = { 'NAME': os.path.join(BASE_DIR, 'db-local.sqlite3'), } } -#DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.postgresql_psycopg2', -# 'NAME': 'mam_local', -# 'USER': 'mam', -# }, -#} +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'mam-test', + 'USER': 'kam', + }, +} # LOGGING LOGGING = { diff --git a/seminar/migrations/0060_spoj_stromy.py b/seminar/migrations/0060_spoj_stromy.py index 59b2943d..d0826ca1 100644 --- a/seminar/migrations/0060_spoj_stromy.py +++ b/seminar/migrations/0060_spoj_stromy.py @@ -6,6 +6,15 @@ from django.db import migrations from django.db.models import Q +def nastav_koren(koren, node): + node.root = koren + node.save() + + if node.succ: + nastav_koren(koren, node.succ) + if node.first_child: + nastav_koren(koren, node.first_child) + def pridej_potomka(rodic, potomek): # Daný vrchol bude posledním potomkem rodiče uz_ma_deti = False @@ -23,8 +32,7 @@ def pridej_potomka(rodic, potomek): posledni = posledni.succ # Nastavíme kořen: - potomek.root = rodic.root - potomek.save() + nastav_koren(rodic.root, potomek) # Připojíme vrchol: if uz_ma_deti: