[Answer]-Django admin process file after upload complete

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.

How to use upload_to

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)

Leave a comment