mirror of https://github.com/django/django.git
Fixed #30259 -- Fixed crash of admin views when properties don't have admin_order_field attribute.
This commit is contained in:
parent
93daed25a4
commit
7cbcf2e2cb
|
@ -130,7 +130,7 @@ def result_headers(cl):
|
|||
admin_order_field = getattr(attr, "admin_order_field", None)
|
||||
# Set ordering for attr that is a property, if defined.
|
||||
if isinstance(attr, property) and hasattr(attr, 'fget'):
|
||||
admin_order_field = getattr(attr.fget, 'admin_order_field')
|
||||
admin_order_field = getattr(attr.fget, 'admin_order_field', None)
|
||||
if not admin_order_field:
|
||||
is_field_sortable = False
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ class ArticleAdmin(admin.ModelAdmin):
|
|||
list_display = (
|
||||
'content', 'date', callable_year, 'model_year', 'modeladmin_year',
|
||||
'model_year_reversed', 'section', lambda obj: obj.title,
|
||||
'order_by_expression', 'model_property_year',
|
||||
'order_by_expression', 'model_property_year', 'model_month',
|
||||
)
|
||||
list_editable = ('section',)
|
||||
list_filter = ('date', 'section')
|
||||
|
|
|
@ -60,6 +60,10 @@ class Article(models.Model):
|
|||
property_year.admin_order_field = 'date'
|
||||
model_property_year = property(property_year)
|
||||
|
||||
@property
|
||||
def model_month(self):
|
||||
return self.date.month
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue