Sunday, March 27, 2011

Re: Updating to Django 1.3 - how to preserve file field previous behaviour

On Sun, Mar 27, 2011 at 6:20 PM, -RAX- <michele.sama@gmail.com> wrote:
> Hi all,
>
> According to http://docs.djangoproject.com/en/dev/releases/1.3/#filefield-no-longer-deletes-files
> FileField fields no longer delete the related file when the instance
> is deleted.
>
> I understand the motivations behind this decision BUT this creates
> several side effects in various websites which I have developed.
>
> Is it there a way to keep the original behaviour?
>
> If not, which one in your opinion is the best way to delete files when
> the owning instance has been deleted?
> A post delete signal? Will this suffer from the original problem for
> which the file deletion has been removed?

As was suggested when you raised this on django-dev, if you want the
old behavior, write a subclass of FileField that reintroduces the old
behavior.

The changeset that removed the old behavior is fairly simple to
understand, and can be easily used as a template for the changes you
need to make:

http://code.djangoproject.com/changeset/15321

This code attaches a post-delete signal to any model that uses the
field (using the contribute_to_class method), and provides a deletion
method to remove the file.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate