Code

Opened 5 years ago

Closed 5 years ago

#10044 closed (fixed)

FileField should accept assignment of File objects

Reported by: Gulopine Owned by: Gulopine
Component: File uploads/storage Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

Currently, FileField attributes can only receive new File content by way of the save() method, which commits the file to storage immediately. In order to support model validation, and perhaps elsewhere, these attributes should be able to accept a File object directly and delay saving them to storage until the model instance is saved.

Attachments (2)

10044.diff (4.8 KB) - added by Gulopine 5 years ago.
Updated FieldFile to accept File objects through attribute assignment, saving them automatically when the associated instance is saved
10044.2.diff (5.3 KB) - added by Gulopine 5 years ago.
Removed the save_form_data() override in FileField, now that the standard behavior is sufficient for populating a model from a form (and delaying the save is better typically, anyway)

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by Gulopine

Updated FieldFile to accept File objects through attribute assignment, saving them automatically when the associated instance is saved

Changed 5 years ago by Gulopine

Removed the save_form_data() override in FileField, now that the standard behavior is sufficient for populating a model from a form (and delaying the save is better typically, anyway)

comment:1 Changed 5 years ago by jacob

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

(In [9766]) Fixed #10044: You can now assign directly to file fields (instance.filefield = somefile). Thanks, Marty Alchin.

comment:2 Changed 5 years ago by AndrewIngram

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Resolution fixed deleted
  • Status changed from closed to reopened

The patch breaks the behavior of the width_field and height_field properties of ImageField when using the admin.

See this thread for details: http://groups.google.com/group/django-users/browse_thread/thread/6fb4b1e8ec37fda3/eaf739b883e66fcf#eaf739b883e66fcf

comment:3 Changed 5 years ago by Alex

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

This bug has been fixed, please open a new ticket since thats a seperate issue(even if it's a consequence of this)(I think a ticket is already open).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.