modocache / django-generate-scaffold

Generate a Django model, views, URLconf, and templates using a single command.
139 stars 39 forks source link

Create view fails on a model with a File attribute #26

Open jseutter opened 12 years ago

jseutter commented 12 years ago

Steps to recreate:

  1. 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
  1. python manage.py runserver
  2. Navigate to the Create View in the browser.
  3. Fill in the form, taking care to choose a file in the file picker.
  4. 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.

modocache commented 12 years ago

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.