kopia lustrzana https://github.com/wagtail/wagtail
Add documentation for searchable snippets
rodzic
97febeb089
commit
c9aa44cc7e
|
@ -6,7 +6,7 @@ Snippets
|
|||
|
||||
Snippets are pieces of content which do not necessitate a full webpage to render. They could be used for making secondary content, such as headers, footers, and sidebars, editable in the Wagtail admin. Snippets are models which do not inherit the ``Page`` class and are thus not organized into the Wagtail tree, but can still be made editable by assigning panels and identifying the model as a snippet with the ``register_snippet`` class decorator.
|
||||
|
||||
Snippets are not search-able or order-able in the Wagtail admin, so decide carefully if the content type you would want to build into a snippet might be more suited to a page.
|
||||
Snippets lack many of the features of pages, such as being orderable in the Wagtail admin or having a defined URL, so decide carefully if the content type you would want to build into a snippet might be more suited to a page.
|
||||
|
||||
Snippet Models
|
||||
--------------
|
||||
|
@ -169,3 +169,30 @@ These child objects are now accessible through the page's ``advert_placements``
|
|||
{% endfor %}
|
||||
|
||||
|
||||
|
||||
Making Snippets Searchable
|
||||
--------------------------
|
||||
|
||||
If a snippet model inherits from ``wagtail.wagtailsearch.index.Indexed``, as described in :ref:`wagtailsearch_indexing_models`, Wagtail will automatically add a search box to the chooser interface for that snippet type. For example, the ``Advert`` snippet could be made searchable as follows:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
...
|
||||
|
||||
from wagtail.wagtailsearch import index
|
||||
|
||||
...
|
||||
|
||||
@register_snippet
|
||||
class Advert(models.Model, index.Indexed):
|
||||
url = models.URLField(null=True, blank=True)
|
||||
text = models.CharField(max_length=255)
|
||||
|
||||
panels = [
|
||||
FieldPanel('url'),
|
||||
FieldPanel('text'),
|
||||
]
|
||||
|
||||
search_fields = [
|
||||
index.SearchField('text', partial_match=True),
|
||||
]
|
||||
|
|
Ładowanie…
Reference in New Issue