Coder Social home page Coder Social logo

bringfido / django-postgres-setfield Goto Github PK

View Code? Open in Web Editor NEW

This project forked from benperlman/django-postgres-setfield

0.0 0.0 0.0 17 KB

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

License: MIT License

Python 100.00%

django-postgres-setfield's Introduction

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.

django-postgres-setfield's People

Contributors

sjamaan avatar benperlman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.