|
@@ -103,6 +103,10 @@ class RestrictedGenericForeignKey(GenericForeignKey):
|
|
|
# We avoid looking for values if either ct_id or fkey value is None
|
|
# We avoid looking for values if either ct_id or fkey value is None
|
|
|
ct_id = getattr(instance, ct_attname)
|
|
ct_id = getattr(instance, ct_attname)
|
|
|
if ct_id is not None:
|
|
if ct_id is not None:
|
|
|
|
|
+ # Check if the content type actually exists
|
|
|
|
|
+ if not self.get_content_type(id=ct_id, using=instance._state.db).model_class():
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
fk_val = getattr(instance, self.fk_field)
|
|
fk_val = getattr(instance, self.fk_field)
|
|
|
if fk_val is not None:
|
|
if fk_val is not None:
|
|
|
fk_dict[ct_id].add(fk_val)
|
|
fk_dict[ct_id].add(fk_val)
|
|
@@ -127,13 +131,14 @@ class RestrictedGenericForeignKey(GenericForeignKey):
|
|
|
if ct_id is None:
|
|
if ct_id is None:
|
|
|
return None
|
|
return None
|
|
|
else:
|
|
else:
|
|
|
- model = self.get_content_type(
|
|
|
|
|
|
|
+ if model := self.get_content_type(
|
|
|
id=ct_id, using=obj._state.db
|
|
id=ct_id, using=obj._state.db
|
|
|
- ).model_class()
|
|
|
|
|
- return (
|
|
|
|
|
- model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
|
|
|
|
|
- model,
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ ).model_class():
|
|
|
|
|
+ return (
|
|
|
|
|
+ model._meta.pk.get_prep_value(getattr(obj, self.fk_field)),
|
|
|
|
|
+ model,
|
|
|
|
|
+ )
|
|
|
|
|
+ return None
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
ret_val,
|
|
ret_val,
|