### Install frontend dependencies Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Install required node packages for frontend development. ```bash npm install ``` -------------------------------- ### Compile documentation Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Install documentation dependencies and generate HTML files using Sphinx. ```bash cd /path/to/wagtail-autocomplete pip install -e .[docs] cd docs make html ``` -------------------------------- ### Preview documentation locally Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Start a simple Python server to view the compiled documentation in a browser. ```bash # from insde of /path/to/wagtail-autocomplete/docs cd _build/html/ python -m http.server 8080 ``` -------------------------------- ### Run test suite Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Install test dependencies and execute the pytest suite. ```bash cd /path/to/wagtail-autocomplete pip install -e .[test] pytest ``` -------------------------------- ### Install Wagtail Autocomplete via pip Source: https://wagtail-autocomplete.readthedocs.io/en/latest/getting_started.html Use this command to install the package in your Python environment. ```bash pip install wagtail-autocomplete ``` -------------------------------- ### Start frontend development watch Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Run Webpack in watch mode to compile JavaScript during development. ```bash npm run start ``` -------------------------------- ### Define AuthorPage and BlogPage models Source: https://wagtail-autocomplete.readthedocs.io/en/latest/basic_usage.html Example models demonstrating a ForeignKey relationship between a BlogPage and an AuthorPage. ```python class AuthorPage(Page): pass class BlogPage(Page): author = models.ForeignKey( 'app_label.AuthorPage', null=True, blank=True, on_delete=models.SET_NULL, ) ``` -------------------------------- ### Internal icontains lookup example Source: https://wagtail-autocomplete.readthedocs.io/en/latest/customization.html Demonstrates the internal query performed by Wagtail Autocomplete when searching for partial text matches. ```python MyModel.objects.filter(my_special_field__icontains='part') ``` -------------------------------- ### Define a Snippet and BlogPage model Source: https://wagtail-autocomplete.readthedocs.io/en/latest/using_other_models.html Example of a standard Django model registered as a snippet and a Page model using SnippetChooserPanel. ```python from django.db import models from wagtail.wagtailadmin.edit_handlers import FieldPanel from wagtail.wagtailcore.models import Page from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel from wagtail.wagtailsnippets.models import register_snippet @register_snippet class Link(models.Model): title = models.CharField(max_length=255) url = models.URLField() panels = [ FieldPanel('title'), FieldPanel('url'), ] class BlogPage(Page): external_link = models.ForeignKey( 'app_label.Link', null=True, blank=True, on_delete=models.SET_NULL, ) content_panels = [ SnippetChooserPanel('external_link'), ] ``` -------------------------------- ### Build production assets Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Create a production-ready build of JavaScript and CSS assets before committing. ```bash npm run build ``` -------------------------------- ### Run full dependency test suite Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Execute tests against all dependency permutations using tox. ```bash tox ``` -------------------------------- ### Run project linters Source: https://wagtail-autocomplete.readthedocs.io/en/latest/contributing.html Execute CSS and JS linters using Wagtail's configuration files. ```bash gem install scss_lint npm run lint:css -- --config /path/to/wagtail/.scss-lint.yml npm run lint:js -- --config /path/to/wagtail/.eslintrc flake8 --config /path/to/wagtail/tox.ini wagtailautocomplete isort --check-only --diff --recursive wagtailautocomplete ``` -------------------------------- ### Implement autocomplete_create method Source: https://wagtail-autocomplete.readthedocs.io/en/latest/customization.html Define this class method to allow users to create new model instances on the fly from the autocomplete widget. ```python from django.db import models from wagtailautocomplete.edit_handlers import AutocompletePanel class MyModel(models.Model): title = models.CharField(max_length=255) @classmethod def autocomplete_create(kls: type, value: str): return kls.objects.create(title=value) ``` -------------------------------- ### Configure AutocompletePanel for selection Source: https://wagtail-autocomplete.readthedocs.io/en/latest/basic_usage.html Replacement for PageChooserPanel using AutocompletePanel. ```python content_panels = Page.content_panels + [ AutocompletePanel('author'), ] ``` -------------------------------- ### Configure URL patterns for Wagtail Autocomplete Source: https://wagtail-autocomplete.readthedocs.io/en/latest/getting_started.html Register the autocomplete URL patterns in your project's urls.py file before the admin and Wagtail core URLs. ```python from django.conf.urls import include, url from wagtail.wagtailcore import urls as wagtail_urls from wagtailautocomplete.urls.admin import urlpatterns as autocomplete_admin_urls urlpatterns = [ # ... url(r'^admin/autocomplete/', include(autocomplete_admin_urls)), url(r'^admin/', include(wagtailadmin_urls)), # ... url(r'', include(wagtail_urls)), ] ``` -------------------------------- ### Configure PageChooserPanel for selection Source: https://wagtail-autocomplete.readthedocs.io/en/latest/basic_usage.html Traditional method for selecting an AuthorPage using PageChooserPanel. ```python content_panels = Page.content_panels + [ PageChooserPanel('author', page_type='app_label.AuthorPage'), ] ``` -------------------------------- ### Implement autocomplete_custom_queryset_filter Source: https://wagtail-autocomplete.readthedocs.io/en/latest/customization.html Define a custom static method to override the default filtering logic and return a specific QuerySet. ```python from django.db import models from django.db.models import QuerySet from wagtailautocomplete.edit_handlers import AutocompletePanel class MyModel(models.Model): my_special_field = models.CharField(max_length=255) def autocomplete_label(self): return self.my_special_field @staticmethod def autocomplete_custom_queryset_filter(search_term: str) -> QuerySet: field_name='my_special_field' filter_kwargs = dict() filter_kwargs[field_name + '__contains'] = search_term return MyModel.objects.filter(**filter_kwargs) ``` -------------------------------- ### Implement multiple selection with ParentalManyToManyField Source: https://wagtail-autocomplete.readthedocs.io/en/latest/basic_usage.html Using AutocompletePanel with a ClusterableModel and ParentalManyToManyField for multiple selection. ```python from django.db import models from wagtail.core.models import Page from modelcluster.models import ClusterableModel from modelcluster.fields import ParentalManyToManyField from wagtailautocomplete.edit_handlers import AutocompletePanel class Book(ClusterableModel): title = models.CharField(max_length=255) class AuthorPage(Page): books = ParentalManyToManyField( Book, null=True, related_name='authors' ) content_panels = Page.content_panels + [ AutocompletePanel('books', target_model=Book) ] ``` -------------------------------- ### Define autocomplete_label method Source: https://wagtail-autocomplete.readthedocs.io/en/latest/customization.html Customize the display label for model instances in the autocomplete widget. ```python from django.db import models from wagtailautocomplete.edit_handlers import AutocompletePanel class MyModel(models.Model): my_special_field = models.CharField(max_length=255) def autocomplete_label(self): return self.my_special_field ``` -------------------------------- ### Define autocomplete_search_field property Source: https://wagtail-autocomplete.readthedocs.io/en/latest/customization.html Specify a model field to use for searching instead of the default 'title' attribute. ```python from django.db import models from wagtailautocomplete.edit_handlers import AutocompletePanel class MyModel(models.Model): my_special_field = models.CharField(max_length=255) autocomplete_search_field = 'my_special_field' ``` -------------------------------- ### Replace SnippetChooserPanel with AutocompletePanel Source: https://wagtail-autocomplete.readthedocs.io/en/latest/using_other_models.html Update the content_panels definition to use AutocompletePanel instead of the default snippet chooser. ```python panels = [ AutocompletePanel('external_link'), ] ``` -------------------------------- ### AutocompletePanel Source: https://wagtail-autocomplete.readthedocs.io/en/latest/basic_usage.html The AutocompletePanel class is used to provide an autocomplete widget for selecting objects in Wagtail admin panels. ```APIDOC ## class wagtailautocomplete.edit_handlers.AutocompletePanel(field_name, target_model='wagtailcore.Page') ### Description Provides an autocomplete interface for selecting objects in Wagtail admin. It replaces the standard PageChooserPanel. ### Parameters - **field_name** (string) - Required - The name of the field on the model. - **target_model** (string or model class) - Optional - Limits the objects an editor can select to a specific model. Defaults to 'wagtailcore.Page'. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.