my others signals working such as updating and creating instance but I am not understanding why it’s not adding members to group?
@receiver(post_save,sender=settings.AUTH_USER_MODEL)
def update_user_profile_from_User_model(sender,instance,created,**kwargs):
if instance.email:
MyAuthors.objects.filter(user=instance).update(user=instance,first_name=instance.first_name,last_name=instance.last_name,email=instance.email,is_blog_author=instance.is_blog_author)
if instance.is_blog_author == True:
my_group = Group.objects.get(name='myauthors')
print("group name: ", my_group )
add_user = my_group.user_set.add(instance)
print("add_user: ", add_user )
print result:
group name: myauthors
add_user: None
I also tried this but didn’t work.
group = Group.objects.get(name='myauthors')
if instance.is_blog_author:
instance.groups.add(group)
instance.save()
#update1 my user model:
class UserManagement(AbstractUser):
is_blog_author = models.BooleanField(default=False)
is_editor = models.BooleanField(default=False)
is_subscriber = models.BooleanField(default=False)
is_customer = models.BooleanField(default=False)
update2
After added following changes my user added to group but not saving.
if instance.is_blog_author == True:
User_id = get_user_model()
user_add_to_group = User_id.objects.get(pk=instance.id)
my_group = Group.objects.get(name='myauthors')
print("group name: ", my_group )
add_user = my_group.user_set.add(user_add_to_group)
print("add_user: ", user_add_to_group )
print result:
group name: myauthors
add_user: aws
how to save in signals ? I tried add_user.save() and getting this error
'NoneType' object has no attribute 'save'