]> rtime.felk.cvut.cz Git - linux-conf-perf.git/commitdiff
Make Django DB layer working
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 26 Feb 2016 14:33:11 +0000 (15:33 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 26 Feb 2016 14:33:11 +0000 (15:33 +0100)
At this point I'm able to use ./manage.py to interact with the database.
Having Django DB layer available as a module from our scripts remains to
be done.

scripts/database/__init__.py [deleted file]
scripts/database/manage.py [deleted file]
scripts/database/settings.py [deleted file]
scripts/lcp_django/database/__init__.py [new file with mode: 0644]
scripts/lcp_django/database/models.py [moved from scripts/database/models.py with 100% similarity]
scripts/lcp_django/database/settings.py [new file with mode: 0644]
scripts/lcp_django/manage.py [new file with mode: 0755]

diff --git a/scripts/database/__init__.py b/scripts/database/__init__.py
deleted file mode 100644 (file)
index cd83541..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-import os
-import sys
-from .settings import *
-from .models import *
-
-import django
-django.setup()
diff --git a/scripts/database/manage.py b/scripts/database/manage.py
deleted file mode 100755 (executable)
index fc9ef57..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env python3
-import os
-import sys
-
-if __name__ == "__main__":
-    
-    # Django searches for module 'database' this adds suitable search path
-    database_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
-    if not database_path in sys.path:
-        sys.path.insert(0, database_path)
-
-    import database.settings
-
-    from django.core.management import execute_from_command_line
-
-    execute_from_command_line(sys.argv)
diff --git a/scripts/database/settings.py b/scripts/database/settings.py
deleted file mode 100644 (file)
index a2a31f2..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-import os
-
-BASE_DIR = os.path.dirname(os.path.abspath(__file__))
-
-from django.conf import settings
-if not settings.configured:
-    settings.configure(
-        INSTALLED_APPS = ['database'],
-            DATABASES = {
-                'default': {
-                    'ENGINE': 'django.db.backends.postgresql_psycopg2',
-                    'HOST': '',
-                    'NAME': 'linux-conf-perf',
-                }
-            },
-            MIDDLEWARE_CLASSES = (
-                )
-            )
diff --git a/scripts/lcp_django/database/__init__.py b/scripts/lcp_django/database/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/scripts/lcp_django/database/settings.py b/scripts/lcp_django/database/settings.py
new file mode 100644 (file)
index 0000000..4a9864c
--- /dev/null
@@ -0,0 +1,22 @@
+import os
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = '34xej!+ag9*nzkoi1$!&0c6of-9%wu5kl8f-6qj4!ld1b@av+1'
+
+# Application definition
+
+INSTALLED_APPS = ['database'] # We want this directory to be a django app
+
+MIDDLEWARE_CLASSES = ()
+
+# Database
+# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
+        'HOST': '',
+        'NAME': 'linux-conf-perf',
+        #'ENGINE': 'django.db.backends.sqlite3',
+        #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+   }
+}
diff --git a/scripts/lcp_django/manage.py b/scripts/lcp_django/manage.py
new file mode 100755 (executable)
index 0000000..e366ba4
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+import os
+import sys
+
+if __name__ == "__main__":
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "database.settings")
+
+    from django.core.management import execute_from_command_line
+
+    execute_from_command_line(sys.argv)