<s> import inspect <EOL> from django . apps import apps <EOL> from django . core import serializers <EOL> from django . core . management import BaseCommand <EOL> from field_history . models import FieldHistory <EOL> from field_history . tracker import FieldHistoryTracker , get_serializer_name <EOL> class Command ( BaseCommand ) : <EOL> help = "<STR_LIT>" <EOL> def handle ( self , * args , ** options ) : <EOL> models = [ ] <EOL> for model in apps . get_models ( ) : <EOL> for member in inspect . getmembers ( model ) : <EOL> if isinstance ( member [ <NUM_LIT:1> ] , FieldHistoryTracker ) : <EOL> models . append ( ( model , member [ <NUM_LIT:1> ] . fields ) ) <EOL> break <EOL> if models : <EOL> self . stdout . write ( '<STR_LIT>' . format ( len ( models ) ) ) <EOL> for model_fields in models : <EOL> model = model_fields [ <NUM_LIT:0> ] <EOL> fields = model_fields [ <NUM_LIT:1> ] <EOL> for obj in model . _default_manager . all ( ) : <EOL> for field in list ( fields ) : <EOL> data = serializers . serialize ( get_serializer_name ( ) , <EOL> [ obj ] , <EOL> fields = [ field ] ) <EOL> FieldHistory . objects . create ( <EOL> object = obj , <EOL> field_name = field , <EOL> serialized_data = data , <EOL> ) <EOL> else : <EOL> self . stdout . write ( '<STR_LIT>' ) </s>
