Skip to main content

Custom field for Django to separate multiple values in database with a separator and retrieve them as list

Project description

Build Status

Custom field for Django to separate multiple values in database with a separator and retrieve them as list.

Compatibility

This library is compatible with:

  • python2.6, django1.4

  • python2.6, django1.5

  • python2.6, django1.6

  • python2.7, django1.4

  • python2.7, django1.5

  • python2.7, django1.6

  • python3.3, django1.5

  • python3.3, django1.6

Installation

  1. Download the package on GitHub or simply install it via PyPi

  2. 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, choices=(('en', 'English'),
                                                                  ('fr', 'French')), token=',')
  3. Sync your database using syncdb command from django command line

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

In [1]: from myapp.models import Project

In [2]: project = Project(name='Foo', languages=['fr', 'en'])

In [3]: project.save() # save 'fr,en' in database for the column "languages"

In [4]: project.pk
1

In [5]: project = Project.objects.get(pk=1)

In [6]: project.languages
['fr', 'en']

Project details


Download files

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

Source Distribution

django-separatedvaluesfield-0.1.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file django-separatedvaluesfield-0.1.tar.gz.

File metadata

File hashes

Hashes for django-separatedvaluesfield-0.1.tar.gz
Algorithm Hash digest
SHA256 8a65088e4af91121e5164600c48b6c3f0393bb00bd3c793506ad1d9ea55adee5
MD5 f45748ea306b2287f0cd7ad0704ced34
BLAKE2b-256 6cb0f4eaddaa59b47fc2fd57544c38414f30ca8bec09876cd8724b99099928f7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page