[Answered ]-Download uploaded files from Django Admin

2👍

you can simply do this

Click to get the code

from django.contrib import admin
from app.models import *

class AppAdmin(admin.ModelAdmin):
    list_display = ('author','title','file_link')
    def file_link(self, obj):
        if obj.file:
            return "<a href='%s' download>Download</a>" % (obj.file.url,)
        else:
            return "No attachment"
    file_link.allow_tags = True
    file_link.short_description = 'File Download'

admin.site.register(AppModel , AppAdmin)

0👍

You need an absolute url inside href, whereas self.cvFile.url will return a relative url. So unless you are on the home page, the link will simply append on to whatever url you are currently on. Simply add the domain url to self.cvFile.url and it should work.

Leave a comment