Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Mutually Exclusive form field wigets for Django

Project Description

# Mutually Exclusive Form Fields
[![Build Status](](

Easily add mutually exclusive fields to Django forms.
## Install
### PyPI
pip install django-xor-formfields

### Source
python install

## Example mutually exclusive form field (TextInput & Select):
# with a widget inference
fields=(forms.TypedChoiceField(choices=[(1,1), (2,2)], coerce=int),

# manual widget creation (allows for the placeholder attr & other customization)
fields=(forms.IntegerField(), forms.IntegerField()),
forms.Select(choices=[(1,1), (2,2)]),
forms.TextInput(attrs={'placeholder': 'Enter a number'}),

## Using FileOrUrlField
This library also includes a more complete field that inherits from
`MutuallyExclusiveValueField` that allows users to upload files via an URL or a
file upload. The field accepts a `to` parameter accepting the following values:
`None, 'url', 'file'`. This value causes the field to perform either no
normalization, normalizatoin to an url (by storing uploaded files as media) or
to a file (by downloading urls to an `InMemoryUploadedFile`).
### Example:
FileOrUrlField(None) # returns UploadedFile objects or URL based on user input
FileOrUrlField(to='file') # always validates to an UploadedFile
FileOrUrlField(to='url', upload_to='foobar') # always validates to an URL
#### AWS note:
The `FileOrUrlField` supports a they keyword argument `no_aws_qs` which
disables aws querystring authorization if using AWS via `django-storages`

## Tests & coverage!
to run the tests simply run:
DJANGO_SETTINGS_MODULE=xorformfields.test_settings test xorformfields

Coverage results are available here:

Release History

This version
History Node


History Node


History Node


History Node


Download Files

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

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(11.4 kB) Copy SHA256 Hash SHA256
2.7 Wheel Jun 8, 2015
(8.8 kB) Copy SHA256 Hash SHA256
Source Jun 8, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting