Initial commit
This commit is contained in:
commit
ce4c240043
9 changed files with 64 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.swp
|
||||
*.pyc
|
||||
__pycache__/
|
1
__init__.py
Normal file
1
__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
default_app_config = 'dbsettings.apps.SettingsConfig'
|
6
admin.py
Normal file
6
admin.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.contrib import admin
|
||||
from dbsettings.models import Setting
|
||||
|
||||
# Register your models here.
|
||||
|
||||
admin.site.register(Setting)
|
6
apps.py
Normal file
6
apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SettingsConfig(AppConfig):
|
||||
name = 'dbsettings'
|
||||
verbose_name = "Application Settings"
|
21
migrations/0001_initial.py
Normal file
21
migrations/0001_initial.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 2.2.6 on 2019-10-26 15:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Setting',
|
||||
fields=[
|
||||
('key', models.CharField(max_length=512, primary_key=True, serialize=False)),
|
||||
('value', models.CharField(max_length=512)),
|
||||
],
|
||||
),
|
||||
]
|
0
migrations/__init__.py
Normal file
0
migrations/__init__.py
Normal file
10
models.py
Normal file
10
models.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Setting(models.Model):
|
||||
key = models.CharField(primary_key=True, max_length=512)
|
||||
value = models.CharField(max_length=512)
|
||||
|
||||
def __str__(self):
|
||||
return self.key
|
3
tests.py
Normal file
3
tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
14
views.py
Normal file
14
views.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from django.shortcuts import render
|
||||
from dbsettings.models import Setting
|
||||
|
||||
def getValue(key):
|
||||
try:
|
||||
return Setting.objects.get(key=key).value
|
||||
except:
|
||||
raise KeyError("No such setting: %s" % key)
|
||||
|
||||
def setValue(key, value):
|
||||
obj = Setting.objects.get_or_create(key=key)[0] # pylint: disable=E1101
|
||||
obj.value = value
|
||||
obj.save()
|
||||
return True
|
Loading…
Reference in a new issue