Django field for storing sets, backed by Postgres arrays
Project description
A Django field for storing standard Python set objects. It uses Postgres arrays as a backing store.
Usage
Using the field is straightforward, and similar to how you’d use a Django ArrayField. You can add the field to your model like so:
from django.db import models
from setfield import SetField
class Person(models.Model):
LANGUAGES = (('NL', 'Dutch'), ('EN', 'English'), ('RU', 'Russian'))
speaks_languages=SetField(models.TextField(choices=LANGUAGES), default=list, blank=True)
Then later, you can use it:
piet = Person(languages={'NL'})
piet.save()
john = Person(languages={'RU', 'EN'})
john.save()
Lookups
All the standard Django ArrayField lookups are supported.
Caveats
Unlike ArrayFields, SetFields cannot be nested (because sets cannot be nested in Python).
When upgrading an existing ArrayField to a SetField, make sure the entries are sorted using the default sort order of Python for the corresponding object type, if you want to use the __exact lookup. Otherwise you’ll get inconsistent results.
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-postgres-setfield-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99041c82ead927d0e28a5f154fcf99c4666600314780cd8c8adbe061f33eb923 |
|
MD5 | 3a70f7a151a669344917a10de9a5b0fa |
|
BLAKE2b-256 | 216e0cd82e751d29296c72da6e5fc690de84cff6bf6f1318cc086bc590335c2d |
Hashes for django_postgres_setfield-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7d17ae5405933e65415baf6c4a2cf1f2d62ccf1281d807eed3b1e87d3c73740 |
|
MD5 | 4cd0065861e2e500a8fe33dc6ff5ee87 |
|
BLAKE2b-256 | d6ba034bacda17cdae5af5f1f963bc95ab796e8340abd0c85c8da89d8606c733 |