<s> import random <EOL> import string <EOL> from django . db import models <EOL> class MyWrapper ( object ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , self . value ) <EOL> def __unicode__ ( self ) : <EOL> return self . value <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , self . __class__ ) : <EOL> return self . value == other . value <EOL> return self . value == other <EOL> class MyAutoField ( models . CharField ) : <EOL> __metaclass__ = models . SubfieldBase <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> kwargs [ '<STR_LIT:max_length>' ] = <NUM_LIT:10> <EOL> super ( MyAutoField , self ) . __init__ ( * args , ** kwargs ) <EOL> def pre_save ( self , instance , add ) : <EOL> value = getattr ( instance , self . attname , None ) <EOL> if not value : <EOL> value = MyWrapper ( '<STR_LIT>' . join ( random . sample ( string . lowercase , <NUM_LIT:10> ) ) ) <EOL> setattr ( instance , self . attname , value ) <EOL> return value <EOL> def to_python ( self , value ) : <EOL> if not value : <EOL> return <EOL> if not isinstance ( value , MyWrapper ) : <EOL> value = MyWrapper ( value ) <EOL> return value <EOL> def get_db_prep_save ( self , value , connection ) : <EOL> if not value : <EOL> return <EOL> if isinstance ( value , MyWrapper ) : <EOL> return unicode ( value ) <EOL> return value <EOL> def get_db_prep_value ( self , value , connection , prepared = False ) : <EOL> if not value : <EOL> return <EOL> if isinstance ( value , MyWrapper ) : <EOL> return unicode ( value ) <EOL> return value </s>
