Skip to content

Commit

Permalink
Improve hour statistics admin list view
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Sep 11, 2021
1 parent ac5bae6 commit 6189aba
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion dsmr_stats/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,34 @@ class DayStatisticsAdmin(admin.ModelAdmin):
class HourStatisticsAdmin(admin.ModelAdmin):
actions = None
ordering = ['-hour_start']
list_display = ('hour_start', 'electricity_merged', 'electricity_returned_merged')
list_display = (
'hour_start', 'formatted_electricity_merged', 'formatted_electricity_returned_merged', 'formatted_gas'
)
list_filter = (
('hour_start', DateTimeRangeFilter),
)

def formatted_electricity_merged(self, obj: HourStatistics) -> str:
if not obj.electricity_merged:
return '-'

return obj.electricity_merged
formatted_electricity_merged.short_description = 'electricity delivered'

def formatted_electricity_returned_merged(self, obj: HourStatistics) -> str:
if not obj.electricity_returned_merged:
return '-'

return obj.electricity_returned_merged
formatted_electricity_returned_merged.short_description = 'electricity returned'

def formatted_gas(self, obj: HourStatistics) -> str:
if not obj.gas:
return '-'

return obj.gas
formatted_gas.short_description = 'gas'


@admin.register(ElectricityStatistics)
class ElectricityStatisticsAdmin(SingletonModelAdmin):
Expand Down

0 comments on commit 6189aba

Please sign in to comment.