Django - All users added to all groups
i am working to my first django project and i have some problems while creating users. views.py
class registerCrispyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(registerCrispyForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_method = 'POST'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
model = models.UserExt
fields = ('username', 'password')
def register(request):
template_name = 'gestionePrenotazioni/login.html'
formR = registerCrispyForm(request.POST)
context = {'formRegister':formR}
if request.method == 'POST':
if formR.is_valid():
user = formR.save()
user.set_password(request.POST['password'])
user.save()
return redirect("home")
return render(request, template_name, context)
models.py
class UserExt(AbstractUser):
Image = models.ImageField(upload_to='media/users')
abbonamento = models.DateField(null=True, blank=True)
class Meta:
verbose_name_plural = 'Utenti'
When i create a new user he is added to all groups and i can't remove him even in administration panel
I have tried to use
user.groups.clear()
or even to add him only one group but i didn't get any results.
The problem you’re describing, where the user is added to all groups and you can’t remove them, might be related to how the user is being created and saved. Django’s AbstractUser model includes group management by default, so if users are being added to all groups, it could be due to some code logic or settings. enter image description here model