mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
Check for content types with no model classes
This commit is contained in:
parent
4004966b16
commit
1464b075e6
@ -112,9 +112,15 @@ class RestrictedGenericForeignKey(GenericForeignKey):
|
||||
for ct_id, fkeys in fk_dict.items():
|
||||
instance = instance_dict[ct_id]
|
||||
ct = self.get_content_type(id=ct_id, using=instance._state.db)
|
||||
model = ct.model_class()
|
||||
# Skip this content type if the model class doesn't exist. This can happen if
|
||||
# the search index contains data for content types that belong to a plugin
|
||||
# that is no longer installed.
|
||||
if model is None:
|
||||
continue
|
||||
if restrict_params:
|
||||
# Override the default behavior to call restrict() on each model's queryset
|
||||
qs = ct.model_class().objects.filter(pk__in=fkeys).restrict(**restrict_params)
|
||||
qs = model.objects.filter(pk__in=fkeys).restrict(**restrict_params)
|
||||
ret_val.extend(qs)
|
||||
else:
|
||||
# Default behavior
|
||||
@ -130,6 +136,8 @@ class RestrictedGenericForeignKey(GenericForeignKey):
|
||||
model = self.get_content_type(
|
||||
id=ct_id, using=obj._state.db
|
||||
).model_class()
|
||||
if model is None:
|
||||
return None
|
||||
return (
|
||||
model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
|
||||
model,
|
||||
|
Loading…
Reference in New Issue
Block a user