Skip to content

Commit e0383e6

Browse files
authored
add readme
1 parent 05af5c7 commit e0383e6

File tree

5 files changed

+108
-4
lines changed

5 files changed

+108
-4
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Django Dynamic Setting
2+
Django Dynamic Setting is a Django app, designed to help you manage your project settings, storage settings in database, provided admin UI to manage there settings.
3+
4+
# Setup
5+
```sh
6+
pip install git+https://github.com/cuongnb14/django-dynamic-setting@master#egg=django-dynamic-setting
7+
```
8+
9+
Add to install app
10+
```python
11+
INSTALLED_APPS = [
12+
...
13+
"dynamic_setting",
14+
...
15+
]
16+
```
17+
18+
Run migrate
19+
```python
20+
python3 manage.py migrate
21+
```
22+
23+
24+
Define setting in your code
25+
```
26+
# your_app/setting.py
27+
from dynamic_setting.base.fields import IntegerSettingField, BooleanSettingField, CharSettingField
28+
from dynamic_setting.base.settings import Settings
29+
30+
31+
class BotSettings(Settings):
32+
33+
sell_enable = BooleanSettingField(default=1, description='enable sell action')
34+
title = CharSettingField(default="hello", is_public=True)
35+
36+
class Meta:
37+
name = 'bot'
38+
39+
# your_app/apps.py
40+
from django.apps import AppConfig
41+
from dynamic_setting.settings_registry import settings_registry
42+
43+
from .setting import BotSettings
44+
45+
46+
class BotConfig(AppConfig):
47+
name = "cg_bot.bot"
48+
verbose_name = "Bots"
49+
50+
def ready(self):
51+
settings_registry.register(BotSettings)
52+
```
53+
54+
Init setting
55+
```sh
56+
python3 manage.py init_dynamic_setting
57+
```
58+
59+
60+
Use setting
61+
```
62+
setting = BotSettings()
63+
print(setting.title)
64+
```

README.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Generated by Django 5.1 on 2024-09-09 11:20
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = []
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name="DynamicSetting",
15+
fields=[
16+
(
17+
"id",
18+
models.BigAutoField(
19+
auto_created=True,
20+
primary_key=True,
21+
serialize=False,
22+
verbose_name="ID",
23+
),
24+
),
25+
("category", models.CharField(max_length=255)),
26+
("name", models.CharField(max_length=255)),
27+
("value", models.TextField(blank=True)),
28+
(
29+
"description",
30+
models.CharField(
31+
blank=True, default=None, max_length=1000, null=True
32+
),
33+
),
34+
("is_public", models.BooleanField(default=False)),
35+
("created_at", models.DateTimeField(auto_now_add=True)),
36+
("modified_at", models.DateTimeField(auto_now=True)),
37+
],
38+
options={
39+
"unique_together": {("name", "category")},
40+
},
41+
),
42+
]

dynamic_setting/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.core.exceptions import ValidationError
22
from django.db import models
33

4-
class DynamicSetting(TimeStampedModel):
4+
class DynamicSetting(models.Model):
55

66
category = models.CharField(max_length=255)
77
name = models.CharField(max_length=255)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from setuptools import find_packages, setup
33

4-
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
4+
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
55
README = readme.read()
66

77
# allow setup.py to be run from any path

0 commit comments

Comments
 (0)