Skip to main content

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.

Metadata

Release files for django-single-instance-model 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-single-instance-model 1.0.6
File Size Uploaded
django_single_instance_model-1.0.6.tar.gz 2.8 kB Details

Release files / django_single_instance_model-1.0.6.tar.gz

Download URL django_single_instance_model-1.0.6.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5bff47d4e375d36b5dacd8024e462420d6d2c5a472e67c038fc12926ad225d67
BLAKE2b-256 checksum
How to use checksums
7d12cf66dce5d7ebc1012f1b937d75cde9aa1cdfd3935615b9d45ef4315745d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

Release history Release notifications | RSS feed

1.1.0

1 release file

1.0.13

1 release file

1.0.12

1 release file

1.0.11

1 release file

This release

1.0.6 This release

1 release file

1.0.4

1 release file

1.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page