from typing import OrderedDict


def create_object_dictionary(raw_object, fields):
	"""
		Returns a dictionary of an object. Every (valid) 
		field is a key. Each value is in its turn a dictionary
		with the fields 'value' and 'id' (in case the field is 
		represents a ForeignKey). 
	"""
	dict_object = OrderedDict()

	fields_to_be_ignored = []

	# walk over the fields
	for field in fields: 
		try: 
			dict_object[field] = {'value': getattr(raw_object, field.name)}
			if field.get_internal_type() == 'ForeignKey': 
				dict_object[field]['id'] = getattr(raw_object, field.name + '_id')
		except: 
			fields_to_be_ignored.append(field)

	return dict_object, fields_to_be_ignored