Multiple signup, registration forms using django-allauth

邮差的信 提交于 2019-12-03 03:40:31

I'll answer the question as I found the solution to have multiple signup forms with allauth.

Form:

class BusinessSignupForm(SignupForm):
    def save(self, request):
        user = super(BusinessSignupForm, self).save(request)
        user.is_organizer = True
        user.save()
        return user

View

class BusinessUserRegistrationView(SignupView):
    template_name = 'allauth/account/signup-organizer.html'
    form_class = BusinessSignupForm
    redirect_field_name = 'next'
    view_name = 'organisersignup'
    success_url = None

    def get_context_data(self, **kwargs):
        ret = super(BusinessUserRegistrationView, self).get_context_data(**kwargs)
        ret.update(self.kwargs)
        return ret

organisersignup = BusinessUserRegistrationView.as_view()

Template

 <form id="signup_form" method="post" action="{% url 'organisersignup' %}">
      {% csrf_token %}
      {% bootstrap_form form %}
 </form>

This can be reused over and over again to modify properties of the custom user model if you have one.

Currently running Django==1.8.10 and django-allauth==0.24.1

Alex Gustafson

Instead of using user.is_business = True to differentiate types of users consider using a BusinessProfile class. You can have several profile types per user if necessary, for example a PartnerProfile, ClientProfile, SupplierProfile etc. Each profile type can have it's own signup, login, and profile pages.

Here are some alternative solutions: Multiple user type sign up with django-allauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!