1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #5217: Prevent erroneous removal of prefetched GenericForeignKey data from tables

This commit is contained in:
Jeremy Stretch
2020-10-07 13:09:08 -04:00
parent 693b32077a
commit 9738257aa2
2 changed files with 3 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import django_tables2 as tables
from django.contrib.contenttypes.fields import GenericForeignKey
from django.core.exceptions import FieldDoesNotExist
from django.db.models.fields.related import RelatedField
from django.utils.safestring import mark_safe
@ -63,7 +64,7 @@ class BaseTable(tables.Table):
field_path = column.accessor.split('.')
try:
model_field = model._meta.get_field(field_path[0])
if isinstance(model_field, RelatedField):
if isinstance(model_field, (RelatedField, GenericForeignKey)):
prefetch_fields.append('__'.join(field_path))
except FieldDoesNotExist:
pass