Plankton_Detector/PlanktonDetector/DetectionApp/forms.py

34 lines
1.0 KiB
Python
Raw Normal View History

from django import forms
2023-12-19 17:33:46 +01:00
from pyparsing import removeQuotes
2023-12-13 02:11:29 +01:00
from .models import UploadImage
2023-12-19 17:33:46 +01:00
from django.forms import ClearableFileInput, HiddenInput
from django.contrib.auth.models import User
2023-12-13 02:11:29 +01:00
2023-12-19 17:33:46 +01:00
class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True
class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
super().__init__(*args, **kwargs)
def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = single_file_clean(data, initial)
return result
class DetectForm(forms.Form):
image = MultipleFileField()
predicted_image_url = forms.CharField(
max_length=500, widget=HiddenInput(), required=False
)
owner = forms.ModelChoiceField(
queryset=User.objects.all(), widget=HiddenInput(), required=False
)