<s> import logging <EOL> from django . contrib . admin . sites import AlreadyRegistered <EOL> logger = logging . getLogger ( __name__ ) <EOL> def auto_configure_admin ( model ) : <EOL> '''<STR_LIT>''' <EOL> from django . contrib import admin <EOL> from django . db import models <EOL> fields = model . _meta . fields <EOL> field_names = [ f . name for f in fields ] <EOL> list_display = [ f for f in field_names if f not in ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> fields_in_list_display = list_display [ : <NUM_LIT:7> ] <EOL> list_editable_fields = [ <EOL> f . name for f in fields if isinstance ( f , models . IntegerField ) ] <EOL> search_fields_list = [ f . name for f in fields if isinstance ( <EOL> f , ( models . TextField , models . CharField ) ) ] <EOL> class StandardAdmin ( admin . ModelAdmin ) : <EOL> list_display = fields_in_list_display <EOL> list_editable = list_editable_fields <EOL> search_fields = search_fields_list <EOL> return StandardAdmin <EOL> def auto_register ( models_module ) : <EOL> from django . contrib import admin <EOL> from django . db import models <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> variables = dir ( models_module ) <EOL> variables = filter ( lambda x : not x . startswith ( '<STR_LIT>' ) , variables ) <EOL> for x in variables : <EOL> value = getattr ( models_module , x ) <EOL> try : <EOL> model_class = issubclass ( value , models . Model ) <EOL> except TypeError , e : <EOL> model_class = False <EOL> if model_class : <EOL> try : <EOL> admin_config = auto_configure_admin ( value ) <EOL> admin . site . register ( value , admin_config ) <EOL> except Exception , e : <EOL> logger . info ( '<STR_LIT>' , value ) </s>
