@receiver(m2m_changed, sender=LocalSite.users.through)
def _on_local_site_users_changed(sender, instance, model, action, pk_set, **kwargs):
 if (action == u'post_add'):
  if isinstance(instance, User):
   users = [instance]
   local_sites = LocalSite.objects.filter(id__in=pk_set)
  else:
   users = User.objects.filter(id__in=pk_set)
   local_sites = [instance]
  for user in users:
   for local_site in local_sites:
    local_site_user_added.send(sender=LocalSite, user=user, local_site=local_site)

@ receiver ( m2m_changed , sender = LocalSite . users . through ) def _on_local_site_users_changed ( sender , instance , model , action , pk_set , ** kwargs ) : if ( action == u'post_add' ) : if isinstance ( instance , User ) : users = [ instance ] local_sites = LocalSite . objects . filter ( id__in = pk_set ) else : users = User . objects . filter ( id__in = pk_set ) local_sites = [ instance ] for user in users : for local_site in local_sites : local_site_user_added . send ( sender = LocalSite , user = user , local_site = local_site )
handle the m2m_changed event for localsite and user .