fix: no nested subscriptions on the user model

This commit is contained in:
Jean-Baptiste Pasquier 2020-10-01 11:40:46 +02:00
parent 4d5b61602d
commit 63b437e9d9

View File

@ -2,6 +2,7 @@ import logging
import requests
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.mail import send_mail
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
@ -77,6 +78,10 @@ def create_nested_subscribers(sender, instance, created, **kwargs):
local = Model.resolve(instance.object.replace(settings.SITE_URL, ''))[0]
nested_fields = Model.get_meta(local, 'nested_fields', [])
# Don't create nested subscriptions for user model (Notification loop issue)
if local._meta.model_name == get_user_model()._meta.model_name:
return
for nested_field in nested_fields:
try:
field = local._meta.get_field(nested_field)