Skip to main content

django-separatedvaluesfield

Build Status

Alternative to CommaSeparatedIntegerField built-in field that supports MultipleChoiceField, custom separator and returns values as list.

Installation

Install package from PyPi:

pip install django-separatedvaluesfield

Or download the archive from GitHub and proceed to a manual installation:

curl -L https://github.com/thoas/django-separatedvaluesfield/tarball/master | tar zx
cd thoas-django-separatedvaluesfield
python setup.py install

Add SeparatedValuesField to your Django model:

# models.py
from django.db import models

from separatedvaluesfield.models import SeparatedValuesField

class Project(models.Model):
    name = models.CharField(max_length=150)
    languages = SeparatedValuesField(
        max_length=150,
        token=',',
        choices=(
            ('en', 'English'),
            ('fr', 'French')))

If your choices values are not strings, add the cast option with the type you want to apply on values (defaults to django.utils.six.text_type):

# models.py
from django.db import models

from separatedvaluesfield.models import SeparatedValuesField

class Project(models.Model):
    name = models.CharField(max_length=150)
    languages = SeparatedValuesField(
        max_length=150,
        cast=int,
        token=',',
        choices=(
            (1, 'English'),
            (2, 'French')))

If you are running Django <= 1.6, synchronize your database using syncdb:

python manage.py syncdb

If you are running Django >= 1.7, synchronize your database using migrate:

python manage.py migrate

The SeparatedValuesField behaves like a CharField which separates values with a token (default is ,).

This field is transformed as a MultipleChoiceField when you are creating a forms.ModelForm with your model.

Usage

>>> from myapp.models import Project
>>> project = Project(name='Project with strings', languages=['fr', 'en'])
>>> project.save() # save 'fr,en' in database for the column "languages"
>>> project.pk
1

>>> project = Project.objects.get(pk=1)
>>> project.languages
['fr', 'en']

# If you added "cast" option to the field to cast to 'int'
>>> project = Project(name='Project with integers', languages=[u'1', u'2'])
>>> project.save() # save '1,2' in database for the column "languages"
>>> project = Project.objects.get(pk=1)
>>> project.languages
[1, 2]

Contribute

  1. Fork the repository

  2. Clone your fork

  3. Create a dedicated branch (never ever work in master)

  4. Create your development environment with make dev

  5. Activate your environment with source .venv/bin/activate

  6. Make modifications

  7. Write tests and execute them with make test

  8. Be sure all test pass with tox

  9. If all tests pass, submit a pull request

Metadata

Release files for django-separatedvaluesfield 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-separatedvaluesfield 0.6.0
File Size Uploaded Provenance Actions
django-separatedvaluesfield-0.6.0.tar.gz 5.6 kB Without provenance Details for django-separatedvaluesfield-0.6.0.tar.gz

Release files / django-separatedvaluesfield-0.6.0.tar.gz

Download URL django-separatedvaluesfield-0.6.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
15cf53a287e6c3ca492fb78aed040a683df037cc5aabe32e95292aed02efc59b
BLAKE2b-256 checksum
How to use checksums
a180fdcd24f188a5e79ee1648f152249d52bb9c0327d0ac2e0d8de6aaaa31f59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for django-separatedvaluesfield 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page