Skip to main content

Adds simple preferences to the admin panel on Django 3.1 and above

Project description

Django 3 Preferences

A Django app and fork of django_preferences allowing the creation of site preferences in the Django admin panel

What does it do?

Provides a singleton view in the Admin panel for Preferences objects and an interface to allow the preferences to be used in code or in templates.

How is it different from django_preferences?

This is a fork and revision of the django_preferences package, which has not been updated in a number of years. The main changes are:

  1. Since most users only manage one site, the dependency on django.contrib.sites has been removed, which makes for a nicer user experience.
  2. The ability to save and add more records has been disabled in this version, so that only one preferences object can ever exist.
  3. This package is built to work with Django 3.1 and above.

Requirements

  1. Python 3
  2. Django 3.1 and above

Installation

  1. Run pip3 install django3-preferences
  2. Add preferences to your INSTALLED_APPS
  3. If you want your preferences exposed in your templates, then add the preferences.context_processors.preferences_context_processor to your TEMPLATES > OPTIONS > context-processors setting:
TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                'preferences.context_processors.preferences_context_processor',
            ],
        },
    },
]

Usage

To create preferences for your app, create a Django model with the model inheriting from preferences.models.Preferences.

from django.db import models
from preferences.models import Preferences

class SitePreferences(Preferences):
    logged_in_user_can_view = models.BooleanField(default=False)

You can then access these preferences in views or other modules by importing the preferences module. The preferences are exposed under preferences.<Model_Name>.<Preference_Name>

from preferences import preferences

logged_in_user_can_view = preferences.SitePreferences.logged_in_user_can_view

To manage the preferences in the Admin panel (which is the whole point of installing this package!!), register them in your app's admin.py:

from django.contrib import admin
from preferences.admin import PreferencesAdmin
from <App_Name>.models import SitePreferences

admin.site.register(SitePreferences, PreferencesAdmin)

Finally, if you've added the context processor in step 3 of the usage section, then you can access your preferences in the template by typing:

{{ preferences.SitePreferences.logged_in_user_can_view }}

Credits

Original project: django_preferences

Django 3 revision: Matt Rudge

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

django3-preferences-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django3_preferences-0.0.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file django3-preferences-0.0.1.tar.gz.

File metadata

  • Download URL: django3-preferences-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for django3-preferences-0.0.1.tar.gz
Algorithm Hash digest
SHA256 1157dea18e26c16e42e481c79238f9073e67f64636a2be68cc17af7d5b5b0c23
MD5 b38d7f670427ce00e3270d2c75184c72
BLAKE2b-256 62232232fe70b66f4542ddbec1ed1d1a1f4b2f8112ef1ad8ea4ec49bdfcdc54d

See more details on using hashes here.

File details

Details for the file django3_preferences-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django3_preferences-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for django3_preferences-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e725dad4e499b1ccee9496e7f1fdc09c9a8a0d66fc75527cfd38567d06edfe2
MD5 607cd22e5cc61f37a64f8a4a68f0effd
BLAKE2b-256 236015139015be7d8d12fa265776bc72d626b21debcfc1e2f884b7087d0ffe26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page