# Path: native_tags/decorators.py
# def tag(bucket, doc):
#     def wrapped(inner, **options):


from django.db.models import get_model
from django.template import TemplateSyntaxError
from native_tags.decorators import function
"""
Template tags which can do retrieval of content from any model.

"""



def _get_model(model):
    m = get_model(*model.split('.'))
    if m is None:
        raise TemplateSyntaxError("Generic content tag got invalid model: %s" % model)
    return m

def get_latest_object(model, field=None):
    """
    Retrieves the latest object from a given model, in that model's
    default ordering, and stores it in a context variable.
    The optional field argument specifies which field to get_latest_by, otherwise the model's default is used
    
    Syntax::
    
        {% get_latest_object [app_name].[model_name] [field] as [varname] %}
    
    Example::
    
        {% get_latest_object comments.freecomment submitted_date as latest_comment %}
    
    """
    return _get_model(model)._default_manager.latest(field)

# Path: native_tags/decorators.py
# def tag(bucket, doc):
#     def wrapped(inner, **options):


# Path: native_tags/contrib/generic_content.py
from django.db.models import get_model
from django.template import TemplateSyntaxError
from native_tags.decorators import function

"""
Template tags which can do retrieval of content from any model.

"""



def _get_model(model):
    m = get_model(*model.split('.'))
    if m is None:
        raise TemplateSyntaxError("Generic content tag got invalid model: %s" % model)
    return m

def get_latest_object(model, field=None):
    """
    Retrieves the latest object from a given model, in that model's
    default ordering, and stores it in a context variable.
    The optional field argument specifies which field to get_latest_by, otherwise the model's default is used
    
    Syntax::
    
        {% get_latest_object [app_name].[model_name] [field] as [varname] %}
    
    Example::
    
        {% get_latest_object comments.freecomment submitted_date as latest_comment %}
    
    """
    return _get_model(model)._default_manager.latest(field)

get_latest_object = function(get_latest_object)    