# Path: dynamic_rest/related.py



from itertools import chain
from django.db.models import ManyToOneRel  # tested in 1.9
from django.db.models import OneToOneRel  # tested in 1.9
from django.db.models import (
    ForeignKey,
    ManyToManyField,
    ManyToManyRel,
    OneToOneField
)
from dynamic_rest.related import RelatedObject
            if (f.one_to_many or f.one_to_one)
            and f.auto_created and not f.concrete
        )
        related_m2m_objs = (
            f for f in meta.get_fields(include_hidden=True)
            if f.many_to_many and f.auto_created
        )

        related_objects = {
            o.get_accessor_name(): o
            for o in chain(related_objs, related_m2m_objs)
        }
        if field_name in related_objects:
            return related_objects[field_name]
        else:
            # check virtual fields (1.7)
            if hasattr(meta, 'virtual_fields'):
                for field in meta.virtual_fields:
                    if field.name == field_name:
                        return field

            raise AttributeError(
                '%s is not a valid field for %s' % (field_name, model)
            )


def get_model_field_and_type(model, field_name):
    field = get_model_field(model, field_name)

    # Django 1.7 (and 1.8?)

# Path: dynamic_rest/related.py



# Path: dynamic_rest/meta.py
from itertools import chain
from django.db.models import ManyToOneRel  # tested in 1.9
from django.db.models import OneToOneRel  # tested in 1.9
from django.db.models import (
    ForeignKey,
    ManyToManyField,
    ManyToManyRel,
    OneToOneField
)
from dynamic_rest.related import RelatedObject

            if (f.one_to_many or f.one_to_one)
            and f.auto_created and not f.concrete
        )
        related_m2m_objs = (
            f for f in meta.get_fields(include_hidden=True)
            if f.many_to_many and f.auto_created
        )

        related_objects = {
            o.get_accessor_name(): o
            for o in chain(related_objs, related_m2m_objs)
        }
        if field_name in related_objects:
            return related_objects[field_name]
        else:
            # check virtual fields (1.7)
            if hasattr(meta, 'virtual_fields'):
                for field in meta.virtual_fields:
                    if field.name == field_name:
                        return field

            raise AttributeError(
                '%s is not a valid field for %s' % (field_name, model)
            )


def get_model_field_and_type(model, field_name):
    field = get_model_field(model, field_name)

    # Django 1.7 (and 1.8?)

    if isinstance(field, RelatedObject):