          # not just the field attribute.
          return obj
  
      def to_representation(self, obj):
          value = value_from_object(self.model_field, obj)
          if is_protected_type(value):
              return value
          return self.model_field.value_to_string(obj)
 
</s> remove def is_authenticated(user):
    if django.VERSION < (1, 10):
        return user.is_authenticated()
    return user.is_authenticated


def is_anonymous(user):
    if django.VERSION < (1, 10):
        return user.is_anonymous()
    return user.is_anonymous


def get_related_model(field):
    if django.VERSION < (1, 9):
        return _resolve_model(field.rel.to)
    return field.remote_field.model


def value_from_object(field, obj):
    if django.VERSION < (1, 9):
        return field._get_val_from_obj(obj)
    return field.value_from_object(obj)


# contrib.postgres only supported from 1.8 onwards.
 </s> add # django.contrib.postgres requires psycopg2 </s> remove     for field in [field for field in opts.fields if field.serialize and not get_remote_field(field)]:
 </s> add     for field in [field for field in opts.fields if field.serialize and not field.remote_field]: </s> remove         rel = get_remote_field(self.model_field, default=None)
 </s> add         rel = self.model_field.remote_field </s> remove         # (In Django 1.9+ this differs from previous style)
        if isinstance(model_field, models.DecimalField) and DecimalValidator:
 </s> add         if isinstance(model_field, models.DecimalField): </s> remove             related_model=get_related_model(field),
 </s> add             related_model=field.remote_field.model,
        value = self.model_field.value_from_object(obj)
          # not just the field attribute.
          return obj
  
      def to_representation(self, obj):
        value = self.model_field.value_from_object(obj)
          if is_protected_type(value):
              return value
          return self.model_field.value_to_string(obj)
keep keep keep keep replace keep keep keep
 Remove Django 1.8 & 1.9 compatibility code (#5481)

* Identify code that needs to be pulled out of/removed from compat.py

* Extract modern code from get_names_and_managers in compat.py and remove compat code

* Extract modern code from is_authenticated() in compat.py and remove.

* Extract modern code from is_anonymous() in compat.py and remove

* Extract modern code from get_related_model() from compat.py and remove

* Extract modern code from value_from_object() in compat.py and remove

* Update postgres compat

JSONField now always available.

* Remove DecimalValidator compat

* Remove get_remote_field compat

* Remove template_render compat

Plus isort.

* Remove set_many compat

* Remove include compat 
rest_framework/fields.py