I have a model
class Category(models.Model):
name = models.CharField(unique=True, max_length=45, blank=False, null=False)
perants= models.ManyToManyField('self',through="CategoryParent",symmetrical=False,blank=True)
and the CatigoryPerants
is :
class CategoryParent(models.Model):
chiled_filed=models.ForeignKey("Catigory", on_delete=models.CASCADE,related_name="parent_of_category",blank=False)
parent_filed=models.ForeignKey("Catigory", on_delete=models.CASCADE,blank=False)
and I try to run a signal in signal.py:
@receiver(m2m_changed, sender=Catigory.perants.through )
def CatigoryParentSignals(sender, instance, action, pk_set, **kwargs):
print("Some text or throw Validation Expiation or doin any thing")
The problem is when I add new parent to the Category
from Shell with .parents.set([parents])
or.parants.add(parent)
its work but when add any parent from admin site this signal isn't work
I add the signal.py
in ready
function apps.py
class myappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myapp'
def ready(self) -> None:
import myapp.signals
return super().ready()
and then add myappConfig
to the __init__.py
defult_app_config