📌  相关文章
📜  如何在 django 中设置默认用户组 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:04.181000             🧑  作者: Mango

代码示例1
from django.contrib.auth.models import User, Group
from django.db.models.signals import post_save
from django.dispatch import receiver

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    if created:
        instance.groups.add(Group.objects.get(name='group_name'))