<s> from django . conf import settings <EOL> try : <EOL> from django . contrib . contenttypes . fields import GenericForeignKey <EOL> except ImportError : <EOL> from django . contrib . contenttypes . generic import GenericForeignKey <EOL> from django . core import serializers <EOL> from django . db import models <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from . managers import FieldHistoryManager <EOL> @ python_2_unicode_compatible <EOL> class FieldHistory ( models . Model ) : <EOL> object_id = models . TextField ( db_index = True ) <EOL> content_type = models . ForeignKey ( '<STR_LIT>' , db_index = True ) <EOL> object = GenericForeignKey ( ) <EOL> field_name = models . CharField ( max_length = <NUM_LIT> , db_index = True ) <EOL> serialized_data = models . TextField ( ) <EOL> date_created = models . DateTimeField ( auto_now_add = True , db_index = True ) <EOL> user = models . ForeignKey ( settings . AUTH_USER_MODEL , blank = True , null = True ) <EOL> objects = FieldHistoryManager ( ) <EOL> class Meta : <EOL> app_label = '<STR_LIT>' <EOL> get_latest_by = '<STR_LIT>' <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . field_name , self . object ) <EOL> @ property <EOL> def field_value ( self ) : <EOL> instances = serializers . deserialize ( '<STR_LIT>' , self . serialized_data ) <EOL> instance = list ( instances ) [ <NUM_LIT:0> ] . object <EOL> return getattr ( instance , self . field_name ) </s>
