# Path: bread/utils.py
# def get_model_field(model_instance, spec):
#     if model_instance is None:
#         raise ValueError("None passed into get_model_field")
#     if not isinstance(model_instance, Model):
#         raise ValueError(
#             "%r should be an instance of a model but it is a %s"
#             % (model_instance, type(model_instance))
#         )
# 
#     if spec.startswith("__") and spec.endswith("__"):
#         # It's a dunder method; don't split it.
#         name_parts = [spec]
#     else:
#         name_parts = spec.split("__", 1)
# 
#     value = getattr(model_instance, name_parts[0])
#     if callable(value):
#         value = value()
#     if len(name_parts) > 1 and value is not None:
#         return get_model_field(value, name_parts[1])
#     return value


import logging
from django import template
from django.core.exceptions import ObjectDoesNotExist
from bread.utils import get_model_field



logger = logging.getLogger(__name__)
register = template.Library()


@register.filter(name="getter")
def getter(value, arg):
    """
    Given an object `value`, return the value of the attribute named `arg`.
    `arg` can contain `__` to drill down recursively into the values.
    If the final result is a callable, it is called and its return
    value used.
    """
    try:

# Path: bread/utils.py
# def get_model_field(model_instance, spec):
#     if model_instance is None:
#         raise ValueError("None passed into get_model_field")
#     if not isinstance(model_instance, Model):
#         raise ValueError(
#             "%r should be an instance of a model but it is a %s"
#             % (model_instance, type(model_instance))
#         )
# 
#     if spec.startswith("__") and spec.endswith("__"):
#         # It's a dunder method; don't split it.
#         name_parts = [spec]
#     else:
#         name_parts = spec.split("__", 1)
# 
#     value = getattr(model_instance, name_parts[0])
#     if callable(value):
#         value = value()
#     if len(name_parts) > 1 and value is not None:
#         return get_model_field(value, name_parts[1])
#     return value


# Path: bread/templatetags/bread_tags.py
import logging
from django import template
from django.core.exceptions import ObjectDoesNotExist
from bread.utils import get_model_field




logger = logging.getLogger(__name__)
register = template.Library()


@register.filter(name="getter")
def getter(value, arg):
    """
    Given an object `value`, return the value of the attribute named `arg`.
    `arg` can contain `__` to drill down recursively into the values.
    If the final result is a callable, it is called and its return
    value used.
    """
    try:

        return get_model_field(value, arg)