3 from datetime import datetime
5 from django import forms
6 from django.utils.translation import ugettext_lazy as _
9 from archive.models import Audiobook
10 from archive.settings import FILES_PATH
11 from archive.utils import ExistingFile
13 class AudiobookForm(forms.ModelForm):
17 def save(self, commit=True, path=None):
18 m = super(AudiobookForm, self).save(commit=False)
19 m.modified = datetime.now()
22 # adding a new audiobook
23 if not os.path.isdir(FILES_PATH):
24 os.makedirs(FILES_PATH)
25 # save the file in model
26 m.source_file.save(os.path.basename(path), ExistingFile(path))