i have this method that should signup a new user and that goes well should redirect to “etudiant_login” or if not , to “accueil”. The problem is when i try to add a member to the group “ETUDIANT” it redirects me to “accueil” . I couldnt find anything clear on the django docs on how to add to Groups
Any sort of help would be appreciated
def etudiant_inscription(request):
form = form_etudiant()
if request.method == 'POST':
form = form_etudiant(request.POST)
if form.is_valid():
et = form.save(commit=False)
et.save()
group = Group.objects.get_or_create(name='ETUDIANT')
group.user_set.add(et)
return HttpResponseRedirect('/etudiant_login')
else:
return HttpResponseRedirect('/accueil')
return render(request,‘etudiant_inscription.html’,{‘form’:form})
#models.py
class etudiant(models.Model):
identif = models.CharField(primary_key=True,max_length=20)
nom = models.CharField(max_length=20)
prenom = models.CharField(max_length=20)
date_naissance = models.DateField(blank=True,null=True)
photo = models.ImageField(upload_to=None, height_field=None, width_field=None, max_length=100,blank=True,null=True)
adresse = models.CharField(max_length=50)
email = models.EmailField(max_length=50,null=True,blank=True)
état = models.CharField(max_length=20)
situation = models.CharField(max_length=20)
password = models.CharField(max_length=20)
def __str__(self):
return self.identifiant
#forms.py
class form_etudiant(forms.ModelForm):
class Meta:
model = models.etudiant
fields = '__all__'