Skip to main content

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.


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'})

john = Person(languages={'RU', 'EN'})


All the standard Django ArrayField lookups are supported.


  • 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-postgres-setfield, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_postgres_setfield-0.0.1-py3-none-any.whl (6.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-postgres-setfield-0.0.1.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page