mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Merge pull request #5147 from leewesleyv/feature/4320-extend-inspect-field-labels
Reuse the label_for_field function for fields in the InspectView
This commit is contained in:
commit
5c336f223e
@ -103,7 +103,7 @@ class TestCreateView(TestCase, WagtailTestUtils):
|
|||||||
|
|
||||||
|
|
||||||
class TestInspectView(TestCase, WagtailTestUtils):
|
class TestInspectView(TestCase, WagtailTestUtils):
|
||||||
fixtures = ['test_specific.json']
|
fixtures = ['test_specific.json', 'modeladmintest_test.json']
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.login()
|
self.login()
|
||||||
@ -157,6 +157,16 @@ class TestInspectView(TestCase, WagtailTestUtils):
|
|||||||
response = self.get(100)
|
response = self.get(100)
|
||||||
self.assertEqual(response.status_code, 404)
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
def test_short_description_is_used_as_field_label(self):
|
||||||
|
"""
|
||||||
|
A custom field has been added to the inspect view's `inspect_view_fields` and since
|
||||||
|
this field has a `short_description` we expect it to be used as the field's label,
|
||||||
|
and not use the name of the function.
|
||||||
|
"""
|
||||||
|
response = self.client.get('/admin/modeladmintest/author/inspect/1/')
|
||||||
|
self.assertContains(response, 'Birth information')
|
||||||
|
self.assertNotContains(response, 'author_birth_string')
|
||||||
|
|
||||||
|
|
||||||
class TestEditView(TestCase, WagtailTestUtils):
|
class TestEditView(TestCase, WagtailTestUtils):
|
||||||
fixtures = ['test_specific.json']
|
fixtures = ['test_specific.json']
|
||||||
|
@ -7,7 +7,7 @@ from django.contrib.admin import FieldListFilter, widgets
|
|||||||
from django.contrib.admin.exceptions import DisallowedModelAdminLookup
|
from django.contrib.admin.exceptions import DisallowedModelAdminLookup
|
||||||
from django.contrib.admin.options import IncorrectLookupParameters
|
from django.contrib.admin.options import IncorrectLookupParameters
|
||||||
from django.contrib.admin.utils import (
|
from django.contrib.admin.utils import (
|
||||||
get_fields_from_path, lookup_needs_distinct, prepare_lookup_value, quote, unquote)
|
get_fields_from_path, label_for_field, lookup_needs_distinct, prepare_lookup_value, quote, unquote)
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.core.exceptions import ImproperlyConfigured, PermissionDenied, SuspiciousOperation
|
from django.core.exceptions import ImproperlyConfigured, PermissionDenied, SuspiciousOperation
|
||||||
from django.core.paginator import InvalidPage, Paginator
|
from django.core.paginator import InvalidPage, Paginator
|
||||||
@ -844,14 +844,7 @@ class InspectView(InstanceSpecificView):
|
|||||||
|
|
||||||
def get_field_label(self, field_name, field=None):
|
def get_field_label(self, field_name, field=None):
|
||||||
""" Return a label to display for a field """
|
""" Return a label to display for a field """
|
||||||
label = None
|
return label_for_field(field_name, model=self.model)
|
||||||
if field is not None:
|
|
||||||
label = getattr(field, 'verbose_name', None)
|
|
||||||
if label is None:
|
|
||||||
label = getattr(field, 'name', None)
|
|
||||||
if label is None:
|
|
||||||
label = field_name
|
|
||||||
return label
|
|
||||||
|
|
||||||
def get_field_display_value(self, field_name, field=None):
|
def get_field_display_value(self, field_name, field=None):
|
||||||
""" Return a display value for a field/attribute """
|
""" Return a display value for a field/attribute """
|
||||||
|
@ -9,6 +9,11 @@ class Author(models.Model):
|
|||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
date_of_birth = models.DateField()
|
date_of_birth = models.DateField()
|
||||||
|
|
||||||
|
def author_birth_string(self):
|
||||||
|
return 'This author was born in pallet town'
|
||||||
|
|
||||||
|
author_birth_string.short_description = "Birth information"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class AuthorModelAdmin(ModelAdmin):
|
|||||||
list_filter = ('date_of_birth', )
|
list_filter = ('date_of_birth', )
|
||||||
search_fields = ('name', )
|
search_fields = ('name', )
|
||||||
inspect_view_enabled = True
|
inspect_view_enabled = True
|
||||||
inspect_view_fields = ('name', )
|
inspect_view_fields = ('name', 'author_birth_string')
|
||||||
|
|
||||||
def last_book(self, obj):
|
def last_book(self, obj):
|
||||||
# For testing use of modeladmin methods in list_display
|
# For testing use of modeladmin methods in list_display
|
||||||
|
Loading…
Reference in New Issue
Block a user