def _prepare_value(self, value, dj_field=None):
from django.db import models<EOL>if isinstance(value, (six.string_types, int, float)):<EOL><INDENT>return value<EOL><DEDENT>elif isinstance(value, SimpleLazyObject):<EOL><INDENT>return value.pk<EOL><DEDENT>elif isinstance(value, models.Model):<EOL><INDENT>if dj_field:<EOL><INDENT>if isinstance(dj_field, models.ForeignKey):<EOL><INDENT>return value.pk<EOL><DEDENT><DEDENT>return value<EOL><DEDENT>elif isinstance(value, (ResultSet, EmptyQuerySet, EmptyResultSet, list)):<EOL><INDENT>return [self._prepare_value(v, dj_field=dj_field) for v in value]<EOL><DEDENT>elif isinstance(value, QuerySet):<EOL><INDENT>value = value._clone()<EOL>return [self._prepare_value(v, dj_field=dj_field) for v in value]<EOL><DEDENT>return value<EOL>
Cook the value