Let’s say I have this form:
class SimpleUploadForm(forms.Form):
file = forms.FileField()
I have this model:
class MyModel(models.Model):
first_file = models.FileField(upload_to="uploads/%Y/%m/%d",storage=MyCustomStorage())
second_file = models.FileField(upload_to="uploads/%Y/%m/%d",storage=MyCustomStorage())
for which I also provide a ModelForm. The view part for the SimpleUploadForm is like this:
def simple_upload(request):
...
if request.method == "POST":
form = SimpleUploadForm(request.POST,request.FILES)
if form.is_valid():
# what do I need to do here to save the file in the same place where the `MyModel` ModelForm is saving them?
else:
...
I don’t know how to use the storage and upload_to fields without a ModelForm.
You can use your storage like any other class. Its API is well-documented.
Or you can set DEFAULT_FILE_STORAGE in
settings.py, and it will be used automatically for all your file operations.