python - Django: How to handle Settings Keys in database -


i came across requirement need save settings key, value in database. created model key, value fields. want access these values. first thing came in mind should value database. here example.

class settings(models.model):     key = models.charfield(max_length=50)     value = models.charfield(max_length=100)      @classmethod     def get_key_value(cls, key):         obj = cls.objects.filter(key==key)         if obj.count() > 0:             return obj.first().value;          return none      class meta:         db_table = u'app_settings' 

i think not idea hit database every time. want save list in global variable or session.

how can store data in global?

i dont know approach? please suggest me better way it.

why need save when can access data in settings.py directly?

from django.conf import settings  print settings.some_value 

so there no need save believe


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -