<s> from django . contrib import admin <EOL> from . import models <EOL> class MetricAdmin ( admin . ModelAdmin ) : <EOL> search_fields = ( '<STR_LIT:name>' , ) <EOL> list_filter = ( '<STR_LIT:source>' , ) <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT:source>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_editable = ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( MetricAdmin , self ) . __init__ ( * args , ** kwargs ) <EOL> self . list_display_links = ( None , ) <EOL> def has_add_permission ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def value_display ( self , obj ) : <EOL> return obj . get_value_display ( ) <EOL> value_display . admin_order_field = '<STR_LIT>' <EOL> class MetricGroupAdmin ( MetricAdmin ) : <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> list_display = ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_queryset ( self , request ) : <EOL> """<STR_LIT>""" <EOL> queryset = super ( MetricGroupAdmin , self ) . get_queryset ( request ) <EOL> qs_values = queryset . values ( '<STR_LIT:id>' , '<STR_LIT:name>' ) <EOL> distinct_names = { } <EOL> for metric in qs_values : <EOL> distinct_names [ metric [ '<STR_LIT:name>' ] ] = metric [ '<STR_LIT:id>' ] <EOL> queryset = self . model . objects . filter ( id__in = distinct_names . values ( ) ) <EOL> return queryset <EOL> def save_model ( self , request , obj , form , change ) : <EOL> """<STR_LIT>""" <EOL> like_metrics = self . model . objects . filter ( name = obj . name ) <EOL> updates = { } <EOL> for key in form . changed_data : <EOL> updates [ key ] = form . cleaned_data [ key ] <EOL> like_metrics . update ( ** updates ) <EOL> admin . site . register ( models . Metric , MetricAdmin ) <EOL> admin . site . register ( models . MetricGroup , MetricGroupAdmin ) <EOL> admin . site . register ( models . Source ) </s>
