#17016 closed New feature (fixed)
File uploading documentation leaves out the easiest method for saving a file with a model
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The only source I found for this method of saving a file from a form to a model was on stack overflow. It should be in the documentation so it's easier to find.
Attachments (2)
Change History (7)
by , 14 years ago
| Attachment: | model_file_uploads.diff added |
|---|
comment:1 by , 14 years ago
| Patch needs improvement: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
by , 13 years ago
| Attachment: | 17016.diff added |
|---|
comment:2 by , 13 years ago
| Patch needs improvement: | unset |
|---|
comment:3 by , 13 years ago
Little improvements I'd made:
- Use render instead of render_to_response
- Use explicit relative imports (
from .forms,from .models) UploadFileFormis not imported in the second example
comment:4 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
The patch looks good overall, but I have a few suggestions:
ModelForms first, because they're really the easiest way to save files from a form into a model.ModelWithFileField(file_field=request.FILES['file']). However, you patch talks a lot aboutupload_toand that blurs a bit the message.upload_tois documented in the fields API underFileField; in my opinion it isn't necessary to duplicate the information here.