Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#17016 closed New feature (fixed)

File uploading documentation leaves out the easiest method for saving a file with a model

Reported by: tim.saylor@… Owned by: nobody
Component: Documentation Version: master
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)

model_file_uploads.diff (1.8 KB) - added by tim.saylor@… 3 years ago.
17016.diff (2.5 KB) - added by timo 3 years ago.

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by tim.saylor@…

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

The patch looks good overall, but I have a few suggestions:

  • We should mention ModelForms first, because they're really the easiest way to save files from a form into a model.
  • The key information of this paragraph is this line: ModelWithFileField(file_field=request.FILES['file']). However, you patch talks a lot about upload_to and that blurs a bit the message. upload_to is documented in the fields API under FileField; in my opinion it isn't necessary to duplicate the information here.
  • there's a small typo : reqeust.FILES
  • AUTHORS is sorted alphabetically by last name, first name.

Changed 3 years ago by timo

comment:2 Changed 3 years ago by timo

  • Patch needs improvement unset

comment:3 Changed 3 years ago by claudep

Little improvements I'd made:

  • Use render instead of render_to_response
  • Use explicit relative imports (from .forms, from .models)
  • UploadFileForm is not imported in the second example

comment:4 Changed 3 years ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [eff6ba2f64ea5426502daadb04fbe1e85ace068a]:

Fixed #17016 - Added examples for file uploads in views.

Thanks Tim Saylor for the draft patch and Aymeric Augustin and Claude Paroz for feedback.

comment:5 Changed 3 years ago by Tim Graham <timograham@…>

In [fba0149e1604ad4ab3745abff8bba0d38bbfe321]:

[1.4.X] Fixed #17016 - Added examples for file uploads in views.

Thanks Tim Saylor for the draft patch and Aymeric Augustin and Claude Paroz for feedback.

Backport of eff6ba2f64 from master

Note: See TracTickets for help on using tickets.
Back to Top