0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Ignore tag relations when reference-indexing

This commit is contained in:
Matt Westcott 2022-11-08 15:35:14 +00:00
parent 4013773d06
commit df7442cd60
2 changed files with 19 additions and 0 deletions

View File

@ -1168,6 +1168,16 @@ class TestUsage(TestCase, WagtailTestUtils):
# There's no usage so there should be no table rows
self.assertRegex(response.content.decode("utf-8"), r"<tbody>(\s|\n)*</tbody>")
def test_usage_no_tags(self):
# tags should not count towards an image's references
self.image.tags.add("illustration")
self.image.save()
response = self.client.get(
reverse("wagtailimages:image_usage", args=[self.image.id])
)
# There's no usage so there should be no table rows
self.assertRegex(response.content.decode("utf-8"), r"<tbody>(\s|\n)*</tbody>")
def test_usage_page_with_only_change_permission(self):
home_page = Page.objects.get(id=2)
home_page.add_child(

View File

@ -7,6 +7,7 @@ from django.utils.text import capfirst
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel, get_all_child_relations
from taggit.models import ItemBase
class ReferenceGroups:
@ -495,3 +496,11 @@ class ReferenceIndex(models.Model):
# https://github.com/django/django/blob/7b94847e384b1a8c05a7d4c8778958c0290bdf9a/django/db/models/fields/__init__.py#L858
field_name = field.name.replace("_", " ")
return capfirst(field_name)
# Ignore relations formed by any django-taggit 'through' model, as this causes any tag attached to
# a tagged object to appear as a reference to that object. Ideally we would follow the reference to
# the Tag model so that we can use the references index to find uses of a tag, but doing that
# correctly will require support for ManyToMany relations with through models:
# https://github.com/wagtail/wagtail/issues/9629
ItemBase.wagtail_reference_index_ignore = True