python-django-solo
Port variant py37
Summary Djanjo manipulator of database singletons (PY37)
Package version 1.1.3
Homepage https://github.com/lazybird/django-solo/
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants py38
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 20 APR 2020, 15:00:59 UTC
Port created 02 FEB 2018, 15:29:04 UTC
Subpackage Descriptions
single Django Solo =========== +---------------------------+ | | | | | \ | Django Solo helps working with singletons: | /\ | database tables that only have one row. | >=)'> | Singletons are useful for things like global | \/ | settings that you want to edit from the admin | / | instead of having them in Django settings.py. | | | | +---------------------------+ Features -------- Solo helps you enforce instantiating only one instance of a model in django. * You define the model that will hold your singleton object. * django-solo gives helper parent class for your model and the admin classes. * You get an admin interface that's aware you only have one object. * You can retrieve the object from templates. * By enabling caching, the database is not queried intensively. Use Cases -------- Django Solo is also great for use with singleton objects that have a one to many relationship. Like the use case below where you have a 'Home Slider" that has many "Slides". * Global or default settings * An image slider that has many slides * A page section that has sub-sections * A team bio with many team members There are many cases where it makes sense for the parent in a one to many relationship to be limited to a single instance. Usage Example ```python # models.py from django.db import models from solo.models import SingletonModel class SiteConfiguration(SingletonModel): site_name = models.CharField(max_length=255, default='Site Name') maintenance_mode = models.BooleanField(default=False) def __unicode__(self): return u"Site Configuration" class Meta: verbose_name = "Site Configuration" ` `python # admin.py from django.contrib import admin from solo.admin import SingletonModelAdmin from config.models import SiteConfiguration admin.site.register(SiteConfiguration, SingletonModelAdmin) # There is only one item in the table, you can get it this way: from .models import SiteConfiguration config = SiteConfiguration.objects.get() # get_solo will create the item if it does not already exist config = SiteConfiguration.get_solo() ``` In your model, note how you did not have to provide a `verbose_name_plural` field - That's because Django Solo uses the `verbose_name` instead. If you're changing an existing model (which already has some objects stored in the database) to a singleton model, you can explicitly provide the id of the row in the database for django-solo to use. This can be done by setting `singleton_instance_id` property on the model: ```python class SiteConfiguration(SingletonModel): singleton_instance_id = 24 # (...) ``` Installation
Configuration Switches (platform-specific settings discarded)
PY37 ON Build using Python 3.7 PY38 OFF Build using Python 3.8
Package Dependencies by Type
Build and Runtime python37:single:standard
python-setuptools:single:py37
Download groups
main mirror://PYPI/d/django-solo
Distribution File Information
b1206b9a9411b19a4354f7d7d245909a9ea7e9cd566b594363b5adce7dc13e5d 8865 django-solo-1.1.3.tar.gz
Ports that require python-django-solo:py37
No other ports depend on this one.