mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 00:33:17 +00:00
Alter wagtailadmin.utils.used_by()
wagtailadmin.utils.used_by() no longer assumes that model relationships to pages are named 'page'. Instead it assumes that all ParentalKey relationships are relationships to pages.
This commit is contained in:
parent
6ab88c9b58
commit
d023614d7f
1 changed files with 12 additions and 3 deletions
|
|
@ -1,6 +1,9 @@
|
|||
from wagtail.wagtailcore.models import Page
|
||||
from django.conf import settings
|
||||
|
||||
from modelcluster.fields import ParentalKey
|
||||
|
||||
from wagtail.wagtailcore.models import Page
|
||||
|
||||
|
||||
def used_by(self):
|
||||
"""Returns the pages that an object was used in."""
|
||||
|
|
@ -22,8 +25,10 @@ def used_by(self):
|
|||
for r in related_objects:
|
||||
if isinstance(r, Page):
|
||||
result.append(r)
|
||||
elif hasattr(r, 'page'):
|
||||
result.append(r.page)
|
||||
else:
|
||||
parental_keys = get_parental_keys(r)
|
||||
for parental_key in parental_keys:
|
||||
result.append(getattr(r, parental_key.name))
|
||||
|
||||
return result
|
||||
|
||||
|
|
@ -35,3 +40,7 @@ def usage_count(self):
|
|||
return None
|
||||
|
||||
return len(used_by(self))
|
||||
|
||||
|
||||
def get_parental_keys(obj):
|
||||
return [field for field in obj._meta.fields if type(field) == ParentalKey]
|
||||
|
|
|
|||
Loading…
Reference in a new issue