#NEWLINE# def handle( self , * args , **options ) : #NEWLINE# #INDENT# super ( Command , self ) . handle ( * args , ** options ) #NEWLINE# model_list = sorted ( get_model_list ( ) , key = ( lambda x : ( x ( ) . klass_group , x ( ) . klass_name ) ) ) #NEWLINE# results = [ ] #NEWLINE# for m in model_list : #NEWLINE# #INDENT# if ( self . verbosity > 1 ) : #NEWLINE# #INDENT# self . log ( ' Verifying {0}.{1} fields' . format ( m ( ) . klass_group , m . __name__ ) ) #NEWLINE# #UNINDENT# for f in m . _meta . fields : #NEWLINE# #INDENT# if f . choices : #NEWLINE# #INDENT# for ( value , count ) in m . objects . order_by ( ) . values_list ( f . name ) . annotate ( Count ( f . name ) ) : #NEWLINE# #INDENT# if ( ( value not in [ x [ 0 ] for x in f . choices ] ) and ( value != '' ) and ( value is not None ) ) : #NEWLINE# #INDENT# if ( self . verbosity > 2 ) : #NEWLINE# #INDENT# self . failure ( '  Undefined value for {0}: {1} ({2} occurrences)' . format ( f . name , value , count ) ) #NEWLINE# #UNINDENT# results . append ( ( m ( ) . klass_group , m . __name__ , f . name , value , count ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( results ) > 0 ) : #NEWLINE# #INDENT# self . failure ( '{} undefined choice field values' . format ( len ( results ) ) ) #NEWLINE# table = agate . Table ( results , [ 'group' , 'model' , 'field' , 'undefined_value' , 'occurrences' ] ) #NEWLINE# table . print_table ( max_rows = None , max_column_width = 50 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . success ( 'No undefined choice field values' )