def _django_to_es_field(self, field):
from django.db import models<EOL>prefix = "<STR_LIT>"<EOL>if field.startswith("<STR_LIT:->"):<EOL><INDENT>prefix = "<STR_LIT:->"<EOL>field = field.lstrip("<STR_LIT:->")<EOL><DEDENT>if field in ["<STR_LIT:id>", "<STR_LIT>"]:<EOL><INDENT>return "<STR_LIT>", models.AutoField<EOL><DEDENT>try:<EOL><INDENT>dj_field, _, _, _ = self.model._meta.get_field_by_name(field)<EOL>if isinstance(dj_field, models.ForeignKey):<EOL><INDENT>return prefix + field + "<STR_LIT>", models.ForeignKey<EOL><DEDENT>else:<EOL><INDENT>return prefix + field, dj_field<EOL><DEDENT><DEDENT>except models.FieldDoesNotExist:<EOL><INDENT>pass<EOL><DEDENT>return prefix + field.replace(FIELD_SEPARATOR, "<STR_LIT:.>"), None<EOL>
We use this function in value_list and ordering to get the correct fields name