These are chat archives for django/django

20th
Aug 2016
wqhhust
@wqhhust
Aug 20 2016 08:43
with the admin module, we could use list_display = ('school',...)
to display some columns from the database, but how to display the data as a link? e.g if the column bidding_id value is 123, then I want to show a link to http://someweb/bidding_id/123
Nikita Yaschenko
@Nafanya
Aug 20 2016 08:48
@wqhhust You can define callable returning raw html and pass it to list_display. See in docs: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display
Igor Malinov
@malinich
Aug 20 2016 08:52

@wqhhust

def url_name(obj):
    return Site.objects.get_current().domain + obj.get_absolute_url()
upper_case_name.short_description = 'Name'

class PersonAdmin(admin.ModelAdmin):
    list_display = (url_name,)

i not check this

sorry typo
def url_name(obj):
    return Site.objects.get_current().domain + obj.get_absolute_url()
url_name.short_description = 'Name'

class PersonAdmin(admin.ModelAdmin):
    list_display = (url_name,)
wqhhust
@wqhhust
Aug 20 2016 09:03
I used the following to pass the raw html
def bidding_url(obj):
return '<a href= "http://invest.ppdai.com/loan/info?id=' + obj.bidding_id + '"> test </a>'
but it shows the raw html in the page
and I want it to show a link instead of a raw like <a href= "http://invest.ppdai.com/loan/info?id=18119242"> test </a>
wqhhust
@wqhhust
Aug 20 2016 09:12
this works now:
def bidding_url(obj):
return format_html('<a href= "http://invest.ppdai.com/loan/info?id=' + obj.bidding_id + '"> test </a>')