pax_global_header 0000666 0000000 0000000 00000000064 14704727131 0014520 g ustar 00root root 0000000 0000000 52 comment=fa48979a8e6ece4bfdd439ae2bc37f2076ca6a65
django-solo-2.4.0/ 0000775 0000000 0000000 00000000000 14704727131 0013737 5 ustar 00root root 0000000 0000000 django-solo-2.4.0/.gitattributes 0000664 0000000 0000000 00000000102 14704727131 0016623 0 ustar 00root root 0000000 0000000 # Auto detect text files and perform LF normalization
* text=auto
django-solo-2.4.0/.github/ 0000775 0000000 0000000 00000000000 14704727131 0015277 5 ustar 00root root 0000000 0000000 django-solo-2.4.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14704727131 0017334 5 ustar 00root root 0000000 0000000 django-solo-2.4.0/.github/workflows/python.yml 0000664 0000000 0000000 00000001077 14704727131 0021405 0 ustar 00root root 0000000 0000000 name: python
on: [push, pull_request]
jobs:
tox:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
django-solo-2.4.0/.gitignore 0000664 0000000 0000000 00000000117 14704727131 0015726 0 ustar 00root root 0000000 0000000 *.egg-info
.tox
.idea
__pycache__
*.pyc
venv
dist
files
.mypy_cache
.DS_STORE
django-solo-2.4.0/CHANGES 0000664 0000000 0000000 00000010050 14704727131 0014726 0 ustar 00root root 0000000 0000000 django-solo-2.4.0
=================
Date: 19 October, 2024
* Fix similarly named models from different apps having the same cache key
* Drop support for Python 3.8
* Add support for Python 3.13
* Drop support for end of life Django 3.2
* Add support for Django 5.1
* Improve error handling in template tag
django-solo-2.3.0
=================
Date: 1 July, 2024
* Add typing support
* Deprecate `solo.models.get_cache`
* Switch to `pyproject.toml`
* Switch to Ruff for formatting and linting
django-solo-2.2.0
=================
Date: 1 January, 2024
* Add support for Python 3.12
* Drop support for Python 3.7
* Add support for Django 5.0
* Drop support for end of life Django 4.0 and 4.1
django-solo-2.1.0
=================
Date: 25 May, 2023
* Add support for Django 4.1 and 4.2
* Drop support for end of life Django 2.2
* Add support for Python 3.11
* Drop support for end of life Python 3.6
django-solo-2.0.0
=================
Date: 10 December, 2021
* Add support for Django 4.0
* Drop support for end of life Django versions (only 2.2, 3.2, and 4.0 are supported).
* Add GitHub Actions CI and tox
django-solo-1.2.0
=================
Date: 29 September, 2021
* Make the necessary changes to make the library compatible with Django 3.2
* * *
django-solo-1.1.5
=================
Date: 19 December, 2020
* Fix setup long description - for pypi page
* * *
django-solo-1.1.4
=================
Date: 19 December, 2020
* Now using the same README file github and pypi
* Add pypi badge in Readme
* Add a flag to allow not skipping the admin list page
* Set the zip_safe option to False
* refactor clear_cache into a classmethod
* Added Spanish locale.
* Missing import os added
* update change_form for newer versions of Django
* * *
django-solo-1.1.3
=================
Date: 15 January, 2018
* Merge pull request #64 from the-vishal/patch-2
* Merge pull request #59 from hefting/fix-template-context
* Retrieve app_label from opts in template context - Since Django 1.7
* Fixes #57 -- read SOLO_CACHE_PREFIX from main Django settings
* Merge pull request #56 from girogiro/master
* Fixed #54 -- wrong caching of FileField
* Merge pull request #55 from jaimesanz/master
* Fixed RemovedInDjango20Warning deprecation warning
* Merge pull request #50 from m16a1/patch-1
* .delete() actually deletes now (#48)
* Fix #45 add form_url to change_view (#46)
* Added support for configuring the pk value of the singleton instance (#42)
* * *
django-solo-1.1.2
=================
Date: February 7, 2016
* Documentation update - Elaborated on usage of the template tag
* #37: Update custom_urls in admin.py due to deprecation warning
* #39: Deprecation warning in tests - `TEMPLATES` setting
* * *
django-solo-1.1.1
=================
Date: December 9, 2015
* Add apps module with a basic app config class.
* Change the use of get_cache for Django 1.9.
* Fixed warning messages showing up on Django 1.8.
* Remove 'load url from future' tag from template (1.9).
* Change the way `get_model` is imported.
* * *
django-solo-1.1.0
=================
Date: November 2, 2014
* Fixed warning messages showing up on Django 1.7.
* No need to define a plural name anymore - Pull Request #16.
* Fixed some inconsistent variable names.
* Added 'load url from future' so templates work with Django 1.4 - Pull Request #14.
* * *
django-solo-1.0.5
=================
Date: April 27, 2014
* Pull Request #8: Python3 compatibility issue with `force_unicode` import statement.
* * *
django-solo-1.0.4
=================
Date: November 6, 2013
* Issue #4: Django 1.6 compatibility on `url` and `pattern` import path.
* * *
django-solo-1.0.3
=================
Date: September 14, 2013
* Fixed some packaging issues (licence file).
* * *
django-solo-1.0.2
=================
Date: September 14, 2013
* Fixed some packaging issues.
* * *
django-solo-1.0.1
=================
Date: September 14, 2013
* Added unit tests
* Added support for @override_settings
* Updated doc, licence and packaging
* * *
django-solo-1.0.0
=================
Date: July 11, 2013
* Fist release of django-solo.
* * *
django-solo-2.4.0/LICENSE 0000664 0000000 0000000 00000000406 14704727131 0014744 0 ustar 00root root 0000000 0000000 Licence and Credits
===================
This work was originally founded by [Trapeze][trapeze] and is licensed under a
[Creative Commons Attribution 3.0 Unported][licence].
[licence]: http://creativecommons.org/licenses/by/3.0/
[trapeze]: http://trapeze.com/
django-solo-2.4.0/MANIFEST.in 0000664 0000000 0000000 00000000216 14704727131 0015474 0 ustar 00root root 0000000 0000000 include *.md
include LICENSE
include CHANGES
include solo/py.typed
recursive-include solo/templates *
recursive-include solo/locale *.mo *.po
django-solo-2.4.0/README.md 0000664 0000000 0000000 00000017566 14704727131 0015235 0 ustar 00root root 0000000 0000000
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 __str__(self):
return "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)
```
```python
# 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
------------
This application requires Django 3.2, 4.0, or 4.1.
* Install the package using `pip install django-solo`
* Add ``solo`` or ``solo.apps.SoloAppConfig`` to your ``INSTALLED_APPS`` setting.
This is how you run tests:
./manage.py test solo --settings=solo.tests.settings
And from within `tox`:
```
python -m pip install tox
tox
```
Supported Languages
-------------------
- English
- Spanish
- German
Admin
-----
The standard Django admin does not fit well when working with singleton,
for instance, if you need some global site settings to be edited in the admin.
Django Solo provides a modified admin for that.

* In the admin home page where all applications are listed, we have a `config`
application that holds a singleton model for site configuration.
* The configuration object can only be changed, there's no link for "add" (1).
* The link to the configuration page (2) directly goes to the form page - no
need for an intermediary object list page, since there's only one object.
* The edit page has a modified breadcrumb (3) to avoid linking to the
intermediary object list page.
* From the edit page, we cannot delete the object (4) nor can we add a new one (5).
If you wish to disable the skipping of the object list page, and have the default
breadcrumbs, you should set `SOLO_ADMIN_SKIP_OBJECT_LIST_PAGE` to `False` in your settings.
Availability from templates
---------------------------
The singleton object can be retrieved from template by giving the Django model
dotted path:
```django
{% get_solo 'app_label.ModelName' as my_config %}
```
Example:
```django
{% load solo_tags %}
{% get_solo 'config.SiteConfiguration' as site_config %}
{{ site_config.site_name }}
{{ site_config.maintenance_mode }}
```
If you're extending a template, be sure to use the tag in the proper scope.
Right:
```django
{% extends "index.html" %}
{% load solo_tags %}
{% block content %}
{% get_solo 'config.SiteConfiguration' as site_config %}
{{ site_config.site_name }}
{% endblock content %}
```
Wrong:
```django
{% extends "index.html" %}
{% load solo_tags %}
{% get_solo 'config.SiteConfiguration' as site_config %}
{% block content %}
{{ site_config.site_name }}
{% endblock content %}
```
Caching
-------
By default caching is disabled: every time `get_solo` retrieves the singleton
object, there will be a database query.
You can enable caching to only query the database when initially retrieving the
object. The cache will also be updated when updates are made from the admin.
The cache timeout is controlled via the `SOLO_CACHE_TIMEOUT` settings.
The cache backend to be used is controlled via the `SOLO_CACHE` settings.
Settings
--------
### Template tag name
You can retrieve your singleton object in templates using the `get_solo`
template tag.
You can change the name `get_solo` using the
`GET_SOLO_TEMPLATE_TAG_NAME` setting.
```python
GET_SOLO_TEMPLATE_TAG_NAME = 'get_config'
```
### Admin override flag
By default, the admin is overridden. But if you wish to keep the object list
page (e.g. to customize actions), you can set the `SOLO_ADMIN_SKIP_OBJECT_LIST_PAGE`
to `False`.
```python
SOLO_ADMIN_SKIP_OBJECT_LIST_PAGE = True
```
### Cache backend
Django provides a way to define multiple cache backends with the `CACHES`
settings. If you want the singleton object to be cached separately, you
could define the `CACHES` and the `SOLO_CACHE` settings like this:
```python
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
},
'local': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
},
}
SOLO_CACHE = 'local'
```
Caching will be disabled if set to `None`.
### Cache timeout
The cache timeout in seconds.
```python
SOLO_CACHE_TIMEOUT = 60*5 # 5 mins
```
### Cache prefix
The prefix to use for the cache key.
```python
SOLO_CACHE_PREFIX = 'solo'
```
Getting the code
================
The code is hosted at https://github.com/lazybird/django-solo/
Check out the latest development version anonymously with:
$ git clone git://github.com/lazybird/django-solo.git
You can install the package in the "editable" mode like this:
pip uninstall django-solo # just in case...
pip install -e git+https://github.com/lazybird/django-solo.git#egg=django-solo
You can also install a specific branch:
pip install -e git+https://github.com/lazybird/django-solo.git@my-branch#egg=django-solo
The package is now installed in your project and you can find the code.
To run the unit tests:
pip install tox
tox
### Making a release
1. Update [`solo/__init__.py`](solo/__init__.py) `version`
2. Update [`CHANGES`](./CHANGES)
3. Make a new release on GitHub
4. Upload release to PyPI
```shell
tox -e build
```
```shell
tox -e upload
```
django-solo-2.4.0/docs/ 0000775 0000000 0000000 00000000000 14704727131 0014667 5 ustar 00root root 0000000 0000000 django-solo-2.4.0/docs/images/ 0000775 0000000 0000000 00000000000 14704727131 0016134 5 ustar 00root root 0000000 0000000 django-solo-2.4.0/docs/images/django-solo-admin.jpg 0000664 0000000 0000000 00000352756 14704727131 0022162 0 ustar 00root root 0000000 0000000 JFIF C C i"
} !1AQa"q2#BR$3br
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
w !1AQaq"2B #3Rbr
$4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ? d%cMDžzþYw6ψ45?D[Ǩج!QM3!Ψd8(fthTP/Ƴ"دcBj.ٶ&tc<|[h6YĚ{D-އBh!~k9!)bvHVI# + \Iùl~$ϲ\VXl҆U`s
n!ε5CK ^uL=zj"4ByyGfJ8lN/WakУ$*sՄa^Ik@k~$դSi:<
$1,K&9c3__a_WcZExD.!m. Fd]OL4Y HL36_\/c5fW:Y>o/5fy~0WJx3GdUyrոc1xSZ2w[Gf8L&;
qb5zW
JS^ѯRW'ki_qPNnt<(|mm mv\v]{/?ҤuJ}1|q{?ֵ_/.K
Eմ[m*P5kMǭiiyIWWie$G8
E0rLѫ'Ǝ2T(W5IƴѫQA%t),5u1T_
Me