mirror of
https://github.com/django/django.git
synced 2025-11-20 03:30:00 +00:00
Fixed #25135 -- Deprecated the contrib.admin allow_tags attribute.
Thanks Jaap Roes for the idea and initial patch.
This commit is contained in:
parent
1bbca7961c
commit
f2f8972def
9 changed files with 96 additions and 30 deletions
|
|
@ -18,6 +18,7 @@ from django.core.mail import EmailMessage
|
|||
from django.db import models
|
||||
from django.forms.models import BaseModelFormSet
|
||||
from django.http import HttpResponse, StreamingHttpResponse
|
||||
from django.utils.html import format_html
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.six import StringIO
|
||||
|
||||
|
|
@ -429,7 +430,8 @@ class PostAdmin(admin.ModelAdmin):
|
|||
list_display = ['title', 'public']
|
||||
readonly_fields = (
|
||||
'posted', 'awesomeness_level', 'coolness', 'value',
|
||||
'multiline', 'multiline_html', lambda obj: "foo"
|
||||
'multiline', 'multiline_html', lambda obj: "foo",
|
||||
'multiline_html_allow_tags',
|
||||
)
|
||||
|
||||
inlines = [
|
||||
|
|
@ -444,15 +446,17 @@ class PostAdmin(admin.ModelAdmin):
|
|||
|
||||
def value(self, instance):
|
||||
return 1000
|
||||
value.short_description = 'Value in $US'
|
||||
|
||||
def multiline(self, instance):
|
||||
return "Multiline\ntest\nstring"
|
||||
|
||||
def multiline_html(self, instance):
|
||||
return mark_safe("Multiline<br>\nhtml<br>\ncontent")
|
||||
multiline_html.allow_tags = True
|
||||
|
||||
value.short_description = 'Value in $US'
|
||||
def multiline_html_allow_tags(self, instance):
|
||||
return "Multiline<br>html<br>content<br>with allow tags"
|
||||
multiline_html_allow_tags.allow_tags = True
|
||||
|
||||
|
||||
class FieldOverridePostForm(forms.ModelForm):
|
||||
|
|
@ -574,8 +578,7 @@ class ComplexSortedPersonAdmin(admin.ModelAdmin):
|
|||
ordering = ('name',)
|
||||
|
||||
def colored_name(self, obj):
|
||||
return '<span style="color: #%s;">%s</span>' % ('ff00ff', obj.name)
|
||||
colored_name.allow_tags = True
|
||||
return format_html('<span style="color: #ff00ff;">{}</span>', obj.name)
|
||||
colored_name.admin_order_field = 'name'
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue