Reputation: 59
I am using class based views in my djanog project. i need to assign a group named 'customer' (from django.contrib.auth.Group) at the time of when a user signsup (register)
this is my view for signup
class UserSignup(SuccessMessageMixin, CreateView):
template_name = 'users/signup.html'
success_url = reverse_lazy('home')
form_class = UserSignupForm
success_message = 'Account Created with the name of %{first_name} %{last_name}'
Upvotes: 0
Views: 55
Reputation: 59
figured out by own
we will need to inherit post method and can assign group to user
def post(self, request, *args, **kwargs):
result = super().post(request, *args, **kwargs)
group = Group.objects.get(name='Customer')
group.user_set.add(self.object)
return result
Upvotes: 1