Skip to main content
# Mutually Exclusive Form Fields
[![Build Status](https://travis-ci.org/dschep/django-xor-formfields.svg?branch=master)](https://travis-ci.org/dschep/django-xor-formfields)

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

### Source
```
python setup.py install
```

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

# manual widget creation (allows for the placeholder attr & other customization)
MutuallyExclusiveValueField(
fields=(forms.IntegerField(), forms.IntegerField()),
widget=MutuallyExclusiveRadioWidget(widgets=[
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 django-admin.py test xorformfields
```

Coverage results are available here: https://dschep.github.io/django-xor-formfields/htmlcov/

Metadata

Release files for django-xor-formfields 0.1.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-xor-formfields 0.1.0
File Size Uploaded
django-xor-formfields-0.1.0.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-xor-formfields 0.1.0
File Interpreter ABI Platform
django_xor_formfields-0.1.0-py2-none-any.whl Python 2 none any Details

Total release size: 20.2 kB

Release files / django-xor-formfields-0.1.0.tar.gz

Download URL django-xor-formfields-0.1.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
43210e6f465e7f5e4433dba80311ab1e7cdb3044b8bc1dd621bfbe96c9d518fb
BLAKE2b-256 checksum
How to use checksums
14a55467e0faf2f1a339ee2a43fa056aac1629209252e9140fb77fcae7f8dd00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_xor_formfields-0.1.0-py2-none-any.whl

Download URL django_xor_formfields-0.1.0-py2-none-any.whl
Size 11.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
259415366062ee3b790e7ac7ddbec7606c68e507d422fb565cf3d01aa3cf4e48
BLAKE2b-256 checksum
How to use checksums
7a8f43b04a24b006689c04240d399decc46ce904e1a824cc9fc80bc236e19490
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

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