From the admin panel I can group the user either customer or admin. How do to programmatically? This my function register in views.py.
@unauthenticated_user
def register(request):
form = CreateUserForm()
if request.method == 'POST':
form = CreateUserForm(request.POST)
if form.is_valid():
form.save()
profile = form.save(commit=False)
profile.save()
user = form.cleaned_data.get('username')
us1 = User.objects.filter(username=user).first()
us1.is_staff = True
us1.is_superuser = False
us1.save()
messages.success(request, 'Account was created for ' + user)
return redirect('loginpage')
context = {'form':form}
return render(request, 'register.html', context)
Aucun commentaire:
Enregistrer un commentaire