fnp
/
edumed.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
4f7ac98
)
delete old file when attachment changes
author
Jan Szejko
<janek37@gmail.com>
Tue, 4 Dec 2018 17:43:28 +0000
(18:43 +0100)
committer
Jan Szejko
<janek37@gmail.com>
Tue, 4 Dec 2018 17:43:28 +0000
(18:43 +0100)
contact/forms.py
patch
|
blob
|
history
diff --git
a/contact/forms.py
b/contact/forms.py
index
a9e3366
..
cc60c73
100644
(file)
--- a/
contact/forms.py
+++ b/
contact/forms.py
@@
-1,4
+1,6
@@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
+import os
+
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import UploadedFile
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.core.files.uploadedfile import UploadedFile
@@
-141,7
+143,9
@@
class ContactForm(forms.Form):
email_changed = True
for name, value in self.cleaned_data.items():
if isinstance(value, UploadedFile):
email_changed = True
for name, value in self.cleaned_data.items():
if isinstance(value, UploadedFile):
- Attachment.objects.filter(contact=contact, tag=name).delete() # delete files?
+ for attachment in Attachment.objects.filter(contact=contact, tag=name):
+ os.remove(attachment.file.path)
+ attachment.delete()
attachment = Attachment(contact=contact, tag=name)
attachment.file.save(value.name, value)
attachment.save()
attachment = Attachment(contact=contact, tag=name)
attachment.file.save(value.name, value)
attachment.save()