https://github.com/sainipray/djsingleton
This is useful for create singleton model in django for make global setting.
https://github.com/sainipray/djsingleton
django singleton
Last synced: 7 months ago
JSON representation
This is useful for create singleton model in django for make global setting.
- Host: GitHub
- URL: https://github.com/sainipray/djsingleton
- Owner: sainipray
- License: mit
- Created: 2017-05-05T09:46:26.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-04-01T16:22:30.000Z (almost 4 years ago)
- Last Synced: 2024-10-31T19:42:25.697Z (over 1 year ago)
- Topics: django, singleton
- Language: Python
- Size: 9.77 KB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
===============
Djsingleton
===============
This is useful for create singleton model in django for make global settings.
.. image:: https://img.shields.io/pypi/v/djsingleton.svg
:target: https://pypi.python.org/pypi/djsingleton
.. image:: https://api.travis-ci.org/sainipray/djsingleton.svg
:target: https://travis-ci.org/sainipray/djsingleton/
.. image:: https://img.shields.io/pypi/pyversions/djsingleton.svg
:target: https://travis-ci.org/sainipray/djsingleton/
Overview
========
- SingletonModel - User can work with global settings using singletons.
- SingletonActiveModel - User can save multiple entries but always one entry will active and work as global settings.
Documentation
=============
- Installation -
* Run ::
pip install djsingleton
* Add 'djsingleton' to your INSTALLED_APPS ::
'djsingleton',
- Customization -
* Inherit 'SingletonModel', 'SingletonActiveModel' in your model ::
from djsingleton.models import SingletonModel, SingletonActiveModel
class Config(SingletonModel):
name = models.CharField(max_length=255, null=True, blank=True)
class APIKey(SingletonActiveModel):
key = models.CharField(max_length=255, null=True, blank=True)
* Inherit 'SingletonAdmin', 'SingletonActiveAdmin' in your admin class of model ::
from djsingleton.admin import SingletonAdmin, SingletonActiveAdmin
admin.site.register(Config, SingletonAdmin)
admin.site.register(APIKey, SingletonActiveAdmin)
* In Templates {% load 'djsingleton' %} ::
{% load 'djsingleton' %}
{% get_singleton 'main' 'Config' as object %}
{{ object.name }}
{% get_singleton 'main' 'APIKey' as object %}
{{ object.key }}
Above 'main' > App Label and 'Config' or 'APIKey' > Model Name
Note: In 'SingletonActiveModel' model, You can't delete active row from model. You have to active another row if you want to delete.
License
=======
Djsingleton is an Open Source project licensed under the terms of the `MIT license `_