1👍
✅
So to save file in save_model I just have to call form.save() function in it. Like this:
class MyAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
form.save()
obj.answer = remote_upload(obj.file.path)
obj.save()
So easy =)
👤rush
0👍
You can specify where you want to copy to by setting the upload_to as a function. This can be done in the Model itself.
Example:
def upload_to_special_path(instance, filename):
return #The path that you want to have.
class MyModel(models.Model):
file = models.FileField(upload_to=upload_to_special_path)
Source:stackexchange.com