Guest User

Untitled

a guest
May 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class ModelAdmin(admin.ModelAdmin):
  2. def view_link(obj):
  3. return u"<a href='view/%d/'>View</a>" % obj.id
  4. view_link.short_description = ''
  5. view_link.allow_tags = True
  6. list_display = ('id', view_link)
  7.  
  8. class Person(models.Model):
  9. first_name = models.CharField(max_length=50)
  10. last_name = models.CharField(max_length=50)
  11. color_code = models.CharField(max_length=6)
  12.  
  13. def colored_name(self):
  14. return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
  15. colored_name.allow_tags = True
  16.  
  17. class PersonAdmin(admin.ModelAdmin):
  18. list_display = ('first_name', 'last_name', 'colored_name')
  19.  
  20. def get_absolute_url(self):
  21. return '/profiles/%s/' % (self.id)
  22.  
  23. def profile_link(self):
  24. return '<a href="%s">%s</a>' % (self.get_absolute_url(), self.username)
  25. profile_link.allow_tags = True
  26.  
  27. class PersonAdmin(admin.ModelAdmin):
  28. list_display = ('first_name', 'last_name', 'colored_name', 'profile_link')
Add Comment
Please, Sign In to add comment