def do_tags_for_model(parser, token):
    """
    Retrieves a list of ``Tag`` objects associated with a given model
    and stores them in a context variable.

    Usage::

       {% supertags_for_model [model] as [varname] %}

    The model is specified in ``[appname].[modelname]`` format.

    Extended usage::

       {% supertags_for_model [model] as [varname] with counts %}

    If specified - by providing extra ``with counts`` arguments - adds
    a ``count`` attribute to each tag containing the number of
    instances of the given model which have been tagged with it.

    Examples::

       {% supertags_for_model products.Widget as widget_tags %}
       {% supertags_for_model products.Widget as widget_tags with counts %}
       
       {% supertags_for_model products.Widget as widget_tags with counts product__category__pk=1 %}
       {% supertags_for_model products.Widget as widget_tags with counts product__category__pk=category.pk %}

    """
    bits = token.contents.split()
    len_bits = len(bits)
    if not len_bits > 3:
        raise TemplateSyntaxError(_('%s tag requires more than two arguments') % bits[0])
    if bits[2] != 'as':
        raise TemplateSyntaxError(_("second argument to %s tag must be 'as'") % bits[0])
    if len_bits > 6:
        for i in range(5, len_bits):
            try:
                name, value = bits[i].split('=')
                if name == 'counts':
                    try:
                        kwargs[str(name)] = int(value)
                    except __HOLE__:
                        raise TemplateSyntaxError(_("%(tag)s tag's '%(option)s' option was not a valid integer: '%(value)s'") % {
                            'tag': bits[0],
                            'option': name,
                            'value': value,
                        })
                else:
                    # The remaining bits should be consider extra query params
                    kwargs['filters'][name] = value
                    
            except ValueError:
                raise TemplateSyntaxError(_("%(tag)s tag was given a badly formatted option: '%(option)s'") % {
                    'tag': bits[0],
                    'option': bits[i],
                })
        if bits[4] != 'with':
            raise TemplateSyntaxError(_("if given, fourth argument to %s tag must be 'with'") % bits[0])
        if bits[5] != 'counts':
            raise TemplateSyntaxError(_("if given, fifth argument to %s tag must be 'counts'") % bits[0])
    if len_bits == 4:
        return TagsForModelNode(bits[1], bits[3], counts=False)
    else:
        return TagsForModelNode(bits[1], bits[3], counts=True)
dataset/ETHPy150Open callowayproject/django-supertagging/supertagging/templatetags/supertagging_tags.py/do_tags_for_model