mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #16117 -- Added decorators for admin action and display functions.
Refs #25134, #32099.
This commit is contained in:
parent
83fcfc9ec8
commit
9204485396
18 changed files with 422 additions and 148 deletions
|
@ -3,6 +3,7 @@ from decimal import Decimal
|
|||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin import helpers
|
||||
from django.contrib.admin.utils import (
|
||||
NestedObjects, display_for_field, display_for_value, flatten,
|
||||
|
@ -293,9 +294,9 @@ class UtilsTests(SimpleTestCase):
|
|||
self.assertEqual(label_for_field('site_id', Article), 'Site id')
|
||||
|
||||
class MockModelAdmin:
|
||||
@admin.display(description='not Really the Model')
|
||||
def test_from_model(self, obj):
|
||||
return "nothing"
|
||||
test_from_model.short_description = "not Really the Model"
|
||||
|
||||
self.assertEqual(
|
||||
label_for_field("test_from_model", Article, model_admin=MockModelAdmin),
|
||||
|
@ -323,13 +324,11 @@ class UtilsTests(SimpleTestCase):
|
|||
label_for_field('nonexistent', Article, form=ArticleForm()),
|
||||
|
||||
def test_label_for_property(self):
|
||||
# NOTE: cannot use @property decorator, because of
|
||||
# AttributeError: 'property' object has no attribute 'short_description'
|
||||
class MockModelAdmin:
|
||||
def my_property(self):
|
||||
@property
|
||||
@admin.display(description='property short description')
|
||||
def test_from_property(self):
|
||||
return "this if from property"
|
||||
my_property.short_description = 'property short description'
|
||||
test_from_property = property(my_property)
|
||||
|
||||
self.assertEqual(
|
||||
label_for_field("test_from_property", Article, model_admin=MockModelAdmin),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue