def get_model_field(model, f):
    parts = f.split(LOOKUP_SEP)
    opts = model._meta
    for name in parts[:(- 1)]:
        try:
            rel = opts.get_field_by_name(name)[0]
        except FieldDoesNotExist:
            return None
        if isinstance(rel, ForeignObjectRel):
            if hasattr(rel, 'related_model'):
                opts = rel.related_model._meta
            else:
                opts = rel.opts
        else:
            model = rel.rel.to
            opts = model._meta
    try:
        (rel, model, direct, m2m) = opts.get_field_by_name(parts[(- 1)])
    except FieldDoesNotExist:
        return None
    return rel
def get_model_field(model, f):
    parts = f.split(LOOKUP_SEP)
    opts = model._meta
    for name in parts[:(- 1)]:
        try:
            rel = opts.get_field_by_name(name)[0]
        except FieldDoesNotExist:
            return None
        if isinstance(rel, ForeignObjectRel):
            if hasattr(rel, 'related_model'):
                opts = rel.related_model._meta
            else:
                opts = rel.opts
        else:
            model = rel.rel.to
            opts = model._meta
    try:
        (rel, model, direct, m2m) = opts.get_field_by_name(parts[(- 1)])
    except FieldDoesNotExist:
        return None
    return rel