<s> try : <EOL> from django_extensions . db . fields import CreationDateTimeField <EOL> except : <EOL> CreationDateTimeField = ImportError <EOL> class ClonableMixin ( object ) : <EOL> def clone ( self ) : <EOL> duplicate = self . __class__ ( ) <EOL> for field in self . _meta . fields : <EOL> pk = field . primary_key <EOL> comparator = ( field . name is self . comparator_name ) <EOL> auto_field = isinstance ( field , CreationDateTimeField ) or getattr ( field , '<STR_LIT>' , False ) <EOL> if not ( pk or auto_field or comparator ) : <EOL> value = getattr ( self , field . name ) <EOL> setattr ( duplicate , field . name , value ) <EOL> duplicate . save ( ) <EOL> for field in self . _meta . many_to_many : <EOL> source = getattr ( self , field . attname ) <EOL> destination = getattr ( duplicate , field . attname ) <EOL> for item in source . all ( ) : <EOL> destination . add ( item ) <EOL> return duplicate </s>
