kopia lustrzana https://github.com/wagtail/wagtail
Add documentation for tagging snippets
rodzic
6dc2aecdd0
commit
537502b521
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Ładowanie…
Reference in New Issue