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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-lookup-tables-0.12.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6efdfed0b1af500d41e843aa715d8ac508625446b4db0413231fdcb1334c34c2 |
|
MD5 | 83779db976107078b4964636dc723101 |
|
BLAKE2b-256 | 4d97d7218fea0cbc7ed8e7f0a80197c80123f5c3b0b15583b15153d4e8fc2246 |
Hashes for django_lookup_tables-0.12.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6249880e9ac41da8876a47a7ec6cc5816c19f5d41f1640f642f18396f75b29e5 |
|
MD5 | cd61036259ef92bc761474f44e4a8acf |
|
BLAKE2b-256 | dcf70b28f66dbebed658cb554c72919d95dd9c4df7f91e78d8ffb38a610a52ce |