Commit fece0019 authored by Malcolm Dinsmore's avatar Malcolm Dinsmore

Add examples of ways to use FileDropInput

parent 79840366
# -*- encoding: utf-8 -*-
from base.form_utils import RequiredFieldForm
from django import forms
from base.form_utils import RequiredFieldForm, FileDropInput
from .models import Document
from base.form_utils import FileDropInput
class DocumentForm(RequiredFieldForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for name in ('file', 'description'):
self.fields[name].widget.attrs.update(
{'class': 'pure-input-2-3'}
)
class Meta:
model = Document
fields = (
'file',
'description',
)
# Not required RequiredFieldForm uses FileDropInput for FileField
# widgets = {'file': FileDropInput()}
# this is an example of how to use in a basic ModelForm
class BasicDocumentModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for name in ('file', 'description'):
......@@ -21,3 +41,17 @@ class DocumentForm(RequiredFieldForm):
'description',
)
widgets = {'file': FileDropInput()}
# this is an example of how to use in a basic Form
class NonModelForm(forms.Form):
file = forms.FileField(widget=FileDropInput)
description = forms.CharField(max_length=200)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for name in ('file', 'description'):
self.fields[name].widget.attrs.update(
{'class': 'pure-input-2-3'}
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment