Always have exactly one instance of a model.
Project description
Single Instance Model
Why?
We use Django for a lot of different things including CMS-style projects. In a CMS-style project, the user often needs to be able to just modify some data that shows up on the site. Maybe it's the content of a page.
The concept is simple: There's always going to be exactly one instance of this model.
Installation
To install, pip install django-single-instance-model
.
Usage
In models.py
:
from django.db import models
from single_instance_model.models import SingleInstanceModel
class AboutUs(models.Model, SingleInstanceModel):
text = models.TextField(max_length=2000)
In admin.py
:
from django.contrib import admin
from single_instance_model.admin import SingleInstanceModelAdmin
from . import models
@admin.register(models.AboutUs)
class AboutUsAdmin(SingleInstanceModelAdmin):
pass
Warning
This works by executing code every time a database connection is established. It's a simple check to create the instance of the model if it doesn't exist.. but just be aware.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django_single_instance_model-1.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bff47d4e375d36b5dacd8024e462420d6d2c5a472e67c038fc12926ad225d67 |
|
MD5 | e072957b8d4528b0da09129f577d6448 |
|
BLAKE2b-256 | 7d12cf66dce5d7ebc1012f1b937d75cde9aa1cdfd3935615b9d45ef4315745d2 |