code: def validate(self, instance, value):
          
          if isinstance(value, datetime.datetime):
              return value
          if not isinstance(value, string_types):
              self.error(
                  instance=instance,
                  value=value,
                  extra='Cannot convert non-strings to datetime.',
              )
          try:
              return self.from_json(value)
          except ValueError:
              self.error(
                  instance=instance,
                  value=value,
                  extra='Invalid format for converting to datetime.',
              )
docs: Check if value is a valid datetime object or JSON datetime string