'Returns the requested field by name. Raises FieldDoesNotExist on error.'

def get_field(self, name, many_to_many=True):

    to_search = ((many_to_many and (self.fields + self.many_to_many)) or self.fields)
    for f in to_search:
        if (f.name == name):
            return f
    raise FieldDoesNotExist(('%s    has    no    field    named    %r' % (self.object_name, name)))
