forms.py 709 B

12345678910111213141516171819202122232425
  1. from django import forms
  2. from .models import Media, Thumbnail
  3. from .widgets import ThumbnailRadioSelect
  4. import os
  5. import logging
  6. logger = logging.getLogger('django')
  7. class MediaForm(forms.ModelForm):
  8. #delete = forms.BooleanField(required=False)
  9. def __init__(self, *args, **kwargs):
  10. super().__init__(*args, **kwargs)
  11. self.fields['poster'].choices = [(x.pk,os.path.basename(x.image.name),) for x in self.instance.thumbnail_set.all()]
  12. class Meta:
  13. model = Media
  14. fields = ('title', 'poster', 'tags', 'description')
  15. class UploadForm(forms.Form):
  16. chunked_upload = forms.FileField(label='Pick a file', widget=forms.ClearableFileInput(attrs={'multiple': True}))