Wednesday, January 31, 2018

Re: how to return clickable link in django 2.0 admin.py file

Hi,

Your question is a bit vague - however, if I do my own interpretation of it, you want to return a link from a custom property in django admin?

You can do that specifically by adding the string to a format_html call. See here : https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display
  • from django.db import models  from django.contrib import admin  from django.utils.html import format_html    class Person(models.Model):      first_name = models.CharField(max_length=50)      last_name = models.CharField(max_length=50)      color_code = models.CharField(max_length=6)        def colored_name(self):          return format_html(              '<span style="color: #{};">{} {}</span>',              self.color_code,              self.first_name,              self.last_name,          )    class PersonAdmin(admin.ModelAdmin):      list_display = ('first_name', 'last_name', 'colored_name')
Regards

Andréas

2018-01-31 12:13 GMT+01:00 arvind yadav <developer.arvind2289@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/156eeac6-1c1a-441a-80a3-1eb390e070e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCe0aLcwe65yXS2LrsgHoP%2B1sBTRakPGeHaA8cBDVq605Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment