Skip to main content

Combine all lookup tables into a single unified system.

Project description

Django Lookup Tables

Efficient storage and management of lookup tables used throughout an app.

Note: This package is a work in progress (that's why it's not yet at version 1.0). I am active seeking contributions to help with making it more usable, see "Contributing" below.

Installation

Install the package:

$ pip install django-lookup-tables

Add it to your installed apps:

INSTALLED_APPS = (
    ...
    'lookup_tables',
    ...
)

Usage

The primary use case for lookup tables is to create user-managed lists of options for models to choose from. Consider a model with a field called, for instance, state:

from django.db import models
from lookup_tables.fields import LookupTableItemField

CHOICES = (('draft', 'draft'), ('published', 'published'))

class Post(models.Model):
    title = models.CharField(max_length=100)
    state = models.CharField(choices=CHOICES)

While this is easy to build, changing the choices list requires rebuilding and redeploying your application.

The above model could instead be written as:

from django.db import models
from lookup_tables.fields import LookupTableItemField

class Post(models.Model):
    title = models.CharField(max_length=100)
    state = LookupTableItemField(table_ref='post-state')

This will create a lookup table called "post-state" that has a single option, '<DEFAULT>'. You can now set this field to any value from the LookupTableItems model that references the LookupTable.objects.get(table_ref='post_state') table.

In the admin you will see an entry for 'Lookup Tables'. Here you can manage tables and their associated values. Note that the automatically-generated '<DEFAULT>' item can be renamed or removed; this is just created so that the table is not empty on first use.

django-lookup-tables integrates properly with forms and djangorestframework, so all UI naturally gets up-to-date selection lists just like if you were using a CharField with a choices enum or tuple list.

Each table has an arbitrary list of items. You can order them by setting the "Sort Order" field to any positive integer.

Using with Admin-Sortable2

If you have django-admin-sortable2 installed, you can take advantage of it's UI enhancements by configuring django-lookup-tables to use it. In your settings.py:

INSTALLED_APPS = (
    ...
    'adminsortable2',
    'lookup_tables',
    ...
)

LOOKUP_TABLES = {
    'USE_ADMIN_SORTABLE2': True,
}

Contributing

I am actively seeking contributions to this package. Check the "Issues" section of the repository for my current hit list.

If you have suggestions for other features I am open to hearing them. Use the "Issues" section of the repository to start a conversation.

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

django-lookup-tables-0.12.2.tar.gz (225.6 kB view details)

Uploaded Source

Built Distribution

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

django_lookup_tables-0.12.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file django-lookup-tables-0.12.2.tar.gz.

File metadata

File hashes

Hashes for django-lookup-tables-0.12.2.tar.gz
Algorithm Hash digest
SHA256 ed8b2c94f27e391d3ee35c66468f1e006bb741c56961711ba022da0be5d68db2
MD5 f0169efcf62e30c7c87372f969c6c8ae
BLAKE2b-256 a699ce3434dd125c128d3f65f5ece7de0c0e6d695d874229c6ffcd9d6c7afee2

See more details on using hashes here.

File details

Details for the file django_lookup_tables-0.12.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_lookup_tables-0.12.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a43a1f69d4ad24ada3b0659e3b5c5bc57e6fddbfa7ab2ecd83301be327023a19
MD5 4f4d18edd885dde23aaa3f83fbec066a
BLAKE2b-256 00ea64a35635f016175f52328ada10f6b92cfd0cb4345b8b42f868bbffc56aab

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