Skip to content

Django field plugin for sets, backed by array storage in PostgreSQL

License

Notifications You must be signed in to change notification settings

benperlman/django-postgres-setfield

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-postgres-setfield

https://travis-ci.org/CodeYellowBV/django-postgres-setfield.svg?branch=master

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.

About

Django field plugin for sets, backed by array storage in PostgreSQL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%