Fixed #30259 -- Fixed crash of admin views when properties don't have admin_order_field attribute.

This commit is contained in:
Mariusz Felisiak 2019-04-01 15:11:54 +02:00 committed by GitHub
parent 93daed25a4
commit 7cbcf2e2cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -130,7 +130,7 @@ def result_headers(cl):
admin_order_field = getattr(attr, "admin_order_field", None) admin_order_field = getattr(attr, "admin_order_field", None)
# Set ordering for attr that is a property, if defined. # Set ordering for attr that is a property, if defined.
if isinstance(attr, property) and hasattr(attr, 'fget'): 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: if not admin_order_field:
is_field_sortable = False is_field_sortable = False

View File

@ -104,7 +104,7 @@ class ArticleAdmin(admin.ModelAdmin):
list_display = ( list_display = (
'content', 'date', callable_year, 'model_year', 'modeladmin_year', 'content', 'date', callable_year, 'model_year', 'modeladmin_year',
'model_year_reversed', 'section', lambda obj: obj.title, '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_editable = ('section',)
list_filter = ('date', 'section') list_filter = ('date', 'section')

View File

@ -60,6 +60,10 @@ class Article(models.Model):
property_year.admin_order_field = 'date' property_year.admin_order_field = 'date'
model_property_year = property(property_year) model_property_year = property(property_year)
@property
def model_month(self):
return self.date.month
class Book(models.Model): class Book(models.Model):
""" """