You could remember the old path by saving it as a variable in your
model's __init__ function.
Something like this:
self._old_file_path = self.file_path
Then in your save():
#only if there was a non-blank path to begin with, and it changed
if self._old_file_path and ( self._old_file_path != self.file_path):
os.remove(self._old_file_path
I don't know if this is the best possible solution, but it would
guarantee that this would happen automatically from the admin and your
ModelForms without any extra code.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment