gealogiuya
This commit is contained in:
12
apps/geology/signals/gallery.py
Normal file
12
apps/geology/signals/gallery.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.db.models.signals import m2m_changed
|
||||
from django.dispatch import receiver
|
||||
|
||||
from apps.geology.models import GalleryCategory
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=GalleryCategory.gallery.through)
|
||||
def gallery_category_m2m_changed(sender, instance, action, **kwargs):
|
||||
if action in ["post_add", "post_remove", "post_clear"]:
|
||||
instance.count = instance.gallery.count()
|
||||
print(instance.count)
|
||||
instance.save()
|
||||
Reference in New Issue
Block a user