diff --git a/doc_src/usage.rst b/doc_src/usage.rst index 3bcde13..c54c3b2 100644 --- a/doc_src/usage.rst +++ b/doc_src/usage.rst @@ -2,12 +2,29 @@ Using categories in templates ============================= -To use the template tags::: + +Getting all items within a category +=================================== + +The :py:class:`Category` model automatically gets `reverse relationships `_ with all other models related to it. + +This allows you access to the related objects from the template without altering any views. For example, if you only had ``Entry`` models related to :py:class:`Category`, your ``categories/category_detail.html`` template could look like + +.. literalinclude:: usage_example_template.html + :language: django + :linenos: + + +If you have ``related_name`` parameters to the configuration (see :ref:`registering_models`), then you would use ``category.related_name.all`` instead of ``category.relatedmodel_set.all``\ . + + +Template Tags +============= + +To use the template tags:: {% import category_tags %} -Filters -******* ``tree_info`` ------------- @@ -41,4 +58,5 @@ comma-separated list of feature names. The valid feature names are: Books -> [] Sci-fi -> [u'Books'] - Dystopian Futures -> [u'Books', u'Sci-fi'] \ No newline at end of file + Dystopian Futures -> [u'Books', u'Sci-fi'] + diff --git a/doc_src/usage_example_template.html b/doc_src/usage_example_template.html new file mode 100644 index 0000000..b0bee73 --- /dev/null +++ b/doc_src/usage_example_template.html @@ -0,0 +1,28 @@ +{% extends 'categories/base.html' %} +{% block content %} +

{{ category }}

+{% if category.parent %} +

Go up to + + {{ category.parent }} +

+{% endif %} +{% if category.description %}

{{ category.description }}

{% endif %} +{% if category.children.count %} +

Subcategories

+ +{% endif %} +

Entries

+{% if category.entries_set.all %} + {% for entry in category.entries_set.all %} +

{{ entry.headline }}

+ {% endfor %} +{% else %} +

No entries for {{ category }}

+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/docs/_sources/usage.txt b/docs/_sources/usage.txt index 3bcde13..c54c3b2 100644 --- a/docs/_sources/usage.txt +++ b/docs/_sources/usage.txt @@ -2,12 +2,29 @@ Using categories in templates ============================= -To use the template tags::: + +Getting all items within a category +=================================== + +The :py:class:`Category` model automatically gets `reverse relationships `_ with all other models related to it. + +This allows you access to the related objects from the template without altering any views. For example, if you only had ``Entry`` models related to :py:class:`Category`, your ``categories/category_detail.html`` template could look like + +.. literalinclude:: usage_example_template.html + :language: django + :linenos: + + +If you have ``related_name`` parameters to the configuration (see :ref:`registering_models`), then you would use ``category.related_name.all`` instead of ``category.relatedmodel_set.all``\ . + + +Template Tags +============= + +To use the template tags:: {% import category_tags %} -Filters -******* ``tree_info`` ------------- @@ -41,4 +58,5 @@ comma-separated list of feature names. The valid feature names are: Books -> [] Sci-fi -> [u'Books'] - Dystopian Futures -> [u'Books', u'Sci-fi'] \ No newline at end of file + Dystopian Futures -> [u'Books', u'Sci-fi'] + diff --git a/docs/adding_the_fields.html b/docs/adding_the_fields.html index e5f6586..b1777c6 100644 --- a/docs/adding_the_fields.html +++ b/docs/adding_the_fields.html @@ -6,13 +6,13 @@ - Adding the fields to the database — Django Categories v0.8 documentation + Adding the fields to the database — Django Categories v0.8.2 documentation - +
-

Django Categories v0.8 documentation

+

Django Categories v0.8.2 documentation