#2534: [Patch] Enable FileField/ImageField to be used as core field
--------------------------------+-------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone:
Component: Core framework | Version:
Severity: normal | Keywords:
--------------------------------+-------------------------------------------
This patch gives !FileField (and !ImageField) objects the ability to be
used as 'core' fields in related models. Also added is the ability to
clear the field, deleting the uploaded file from the filesytem.
!FileField and !ImageField objects do not work properly as core fields.
This seems to be acknowledged in {{{manipulators.py}}}, where they are
treated as a special case, but as a result, if a !FileField or !ImageField
is the only field marked {{{core=True}}} in a related model, then that
record will always be saved, even if every field is empty. This patch
corrects this issue by providing a {{{get_manipulator_new_data}}} method
for !FileField which returns the new value that the field will take,
rather than the pre-existing value.
Since {{{core=True}}} fields aren't very useful without the ability to
clear them, this patch also adds the optional ability to delete files
after they've been uploaded. This has been long-standing issue in Django
-- see, for example, Ticket #22. The patch adds a new optional constructor
argument, {{{can_delete}}}, which, when set, will place a checkbox labeled
''Delete'' on the HTML form. When the user checks this checkbox and saves
the form, the !FileField will be cleared and the file associated with the
field will be removed from the filesystem. (Unlike the patch in ticket #22
that provides an HTML link which redirects the user away from the change
form, the ''Delete'' checkbox in this patch does not get processed until
the user saves the object. This also means that the user can choose to
clear a !FileField, make other changes to an object, and save all of the
changes atomically.)
In creating this patch, we have strived to change as little code as
possible. We hope that it will be accepted into Django as it immediately
addresses a significant shortcoming while still maintaining compatibility
with existing models and apps.
This patch is largely based on our work at
[http://www.verdjn.com/wiki/FileField], but goes further by actually
allowing !FileField objects to be used as core fields.
--
Ticket URL: <http://code.djangoproject.com/ticket/2534>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---