Skip to main content
# Multiple-value field for Django forms

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

```
?foo=spam&foo=egg&foo=chips
```
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:
```
?email=foo@bar.com&email=spam@egg.com
```
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
else:
errors = form.errors
# do something with errors
```


Metadata

Release files for django-multivalueformfield 0.0.2

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-multivalueformfield 0.0.2
File Size Uploaded
django_multivalueformfield-0.0.2.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-multivalueformfield 0.0.2
File Interpreter ABI Platform
django_multivalueformfield-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 7.8 kB

Release files / django_multivalueformfield-0.0.2.tar.gz

Download URL django_multivalueformfield-0.0.2.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7044127c151f85dbe08ac38da088b8654525a48b6c4658e6381036167daeab37
BLAKE2b-256 checksum
How to use checksums
c6399dc9e2545a82796b4475b2163944fc0d217b8c144a9e31030130418204c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7rc1

Release files / django_multivalueformfield-0.0.2-py3-none-any.whl

Download URL django_multivalueformfield-0.0.2-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9804effa20b0acb0d0b199f92fa6e3753a022acf9bb1dbd99728d99f685dc8d5
BLAKE2b-256 checksum
How to use checksums
ab0edef3ddadb470530907ea84b1609b7888700167cc401af191e4beb03aa62e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7rc1

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

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