开发者

Django admin proper urls inside listview

开发者 https://www.devze.com 2023-02-04 13:24 出处:网络
My current target is to give users the chance to download CSV files from the admin site of my application.

My current target is to give users the chance to download CSV files from the admin site of my application.

I successfully managed to create an additional column in the model's list view this way:

 def doc_link(self):
    return '<a href="files/%s">%s</a>' % (sel开发者_如何学Cf.output, self.output)
 doc_link.allow_tags = True

This shows the file name and creates the link, but sadly - because it's inside my 'searches' view - it has an URL:

my_site/my_app/searches/files/13.csv.

This is my problem, I would like to have my files stored in the admin media directory, like this:

http://my_site/media/files/13.csv

Does somebody know how to give url which points "outer" from the model's directory? Maybe somehow tell Django to use the ADMIN_MEDIA_PREFIX in the link?

I'd really appreciate any help, thanks!


I feel like you answered your own question : )

What's stopping you from using ADMIN_MEDIA_PREFIX if you want to?

I think it's strange you would use ADMIN_MEDIA_PREFIX since that's where your admin media lives -- you shouldn't be saving anything there, so maybe more like your MEDIA_URL.

from django.conf import settings


def doc_link(self):
    return '<a href="%sfiles/%s">%s</a>' % (settings.MEDIA_URL, self.output, self.output)
 doc_link.allow_tags = True
0

精彩评论

暂无评论...
验证码 换一张
取 消