开发者

django unable to add user to group

I have this user class:

class Parent(User):
    contact_means = models.IntegerField()
    is_active = False
    is_staff = False
    is_superuser = False
    #parent_id = models.AutoField()
    class Meta:
        db_table = 'parent'

During adding of Parent in my admin page, I want开发者_开发知识库 to auto add this parent into a user group:

class ParentAdmin(admin.ModelAdmin):
    def save_model(self,request,modelObj,modelFormIns, change):
        if not change: #new entry
            #save regular parent and user
            parentGroup = Group.objects.get(pk=1)

            modelObj.save()
            modelObj.groups.add(parentGroup)
            #parentGroup.save()
            #save a record under django-registration
            profile_callback = None
            RegistrationProfile.objects.create_inactive_user_from_fk(user = modelObj,send_email = True)

        else:
            modelObj.save()

This doesn't work! no user is added to the group. why?


I figured it might the groups field that could be causing the problem. On adding exclude = ['groups'] to my modeladmin, I do not have any problem. Probably it could be that after adding the group programmatically in my code above, the user groups get flushed after that because on the form itself no groups were selected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜