lostplaces-backend/lostplaces/lostplaces_app/forms.py

38 lines
1.0 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
''' (web)forms that can be used elsewhere. '''
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import Explorer, Place, PlaceImage, Voucher
class ExplorerCreationForm(UserCreationForm):
class Meta:
model = Explorer
fields = ('username', 'email')
class ExplorerChangeForm(UserChangeForm):
class Meta:
model = Explorer
fields = ('username', 'email')
class PlaceForm(forms.ModelForm):
class Meta:
model = Place
fields = '__all__'
exclude = ['submitted_by']
class PlaceImageCreateForm(forms.ModelForm):
class Meta:
model = PlaceImage
fields = ['filename']
widgets = {
'filename': forms.ClearableFileInput(attrs={'multiple': True})
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(self.fields)
self.fields['filename'].required = False