Skip to main content

Multiple-value field for Django forms

Project description

# Multiple-value field for Django forms

## The problem
Say we want to use a Django form to validate form input such as the following:

Django can parse this query-string to generate a list:

>>> request.GET.getlist("foo")
['spam', 'egg', 'chips']

...but it is not yet capable of validating the input using `django.forms`.

## How to use

Say for example, we want to validate a list of email addresses, with a query-string such as the following:
Here are the steps we would take:

1. Install this module (e.g. using `pip install django_multivalueformfield`)
2. Define a form like the following:
import django.forms as forms

from multivaluefield import MultiValueField

class MultiEmailForm(forms.Form):
emails = MultiValueField(forms.EmailField(), "email")
3. Pass the `QueryDict` into the form and validate as per usual:
form = MultiEmailForm(request.GET)
if form.is_valid:
emails = form.cleaned_data["emails"]
# do something with emails
errors = form.errors
# do something with errors

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-multivalueformfield, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_multivalueformfield-0.0.1-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django_multivalueformfield-0.0.1.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page