Add documentation for tagging snippets

pull/1624/head
Tim Heap 2015-08-20 20:54:26 +10:00
rodzic 6dc2aecdd0
commit 537502b521
2 zmienionych plików z 28 dodań i 3 usunięć

Wyświetl plik

@ -155,11 +155,11 @@ Using an example from the Wagtail demo site, here's what the tag model and the r
from modelcluster.fields import ParentalKey
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import Tag, TaggedItemBase
...
from taggit.models import TaggedItemBase
class BlogPageTag(TaggedItemBase):
content_object = ParentalKey('demo.BlogPage', related_name='tagged_items')
...
class BlogPage(Page):
...
tags = ClusterTaggableManager(through=BlogPageTag, blank=True)

Wyświetl plik

@ -169,3 +169,28 @@ These child objects are now accessible through the page's ``advert_placements``
{% endfor %}
Tagging snippets
----------------
Adding tags to snippets is very similar to adding tags to pages. The only difference is that :class:`taggit.manager.TaggableManager` should be used in the place of :class:`~modelcluster.contrib.taggit.ClusterTaggableManager`.
.. code-block:: python
from modelcluster.fields import ParentalKey
from taggit.models import TaggedItemBase
from taggit.managers import TaggableManager
class AdvertTag(TaggedItemBase):
content_object = ParentalKey('demo.Advert', related_name='tagged_items')
@register_snippet
class Advert(models.Model):
...
tags = TaggableManager(through=BlogPageTag, blank=True)
panels = [
...
FieldPanel('tags'),
]
The :ref:`documentation on tagging pages <tagging>` has more information on how to use tags in views.