django-generate-scaffold
django-generate-scaffold copied to clipboard
Create view fails on a model with a File attribute
Steps to recreate:
- Generate a scaffold where one of the model fields is a file type. Eg:
../venv/bin/python manage.py generatescaffold foo Foo name:char description:text screenshot:file
- python manage.py runserver
- Navigate to the Create View in the browser.
- Fill in the form, taking care to choose a file in the file picker.
- Click the Create button. The form displays a message above the file picker: "This field is required."
This was found in a clean virtualenv running Python 2.7, Django 1.4.1 and django-generate-scaffold 0.0.5.
The form needs to have enctype="multipart/form-data" specified, as detailed here: https://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs#basic-file-uploads
I will mark this as a new feature--namely, to determine whether a file field is included in the form and specify the necessary attributes dynamically. Alternatively, if that isn't feasible, to specify enctype="multipart/form-data" on all forms.