I'm new to django, working on a website requiring multiple types of registrations, needing two seperate forms, and basing myself off of cookiecutter-django's template, which utilizes allauth.
I'd still like to retain allauth's email confirmation and password verification.
I've searched around for a solution, coming down to this: Multiple signup, registration forms using django-allauth
It doesn't resolve my problem. The sign up form stays the same in my case. Perhaps only because I'm trying to use the model in the form?
Here's my attempt at a customized log on form:
in cookiecutter's app users/
In models.py:
class Proveedor(models.Model):
TIENE_EMPRESA = (
('S','Si'),
('M','No'),
)
SEXO = (
('F','Femenina'),
('M','Masculino'),
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
oficios = []
ubicacion = models.CharField(_('Ubicacion'),max_length=255)
ubicaciones_servicios = []
tiene_empresa = models.CharField(_('Tienes Empresa?'),max_length=1, choices=TIENE_EMPRESA)
foto = models.ImageField(_('Foto'),upload_to=None, blank=False)
email = models.EmailField(_('Email'),max_length=254)
fecha_nacimiento = models.DateField(_('Fecha de nacimiento'), default=datetime.datetime.now(), blank=True)
sexo = models.CharField(_('Sexo'),max_length=1, choices=SEXO)
telefono = models.CharField(_('Numero de Telefono'),max_length=10)
fotos_trabajos_realizados = []
descripcion_forma_trabajar = models.TextField(_('Descripcion de Forma de Trabajar'),null=True, blank=True)
class Meta:
db_table = 'proveedor'
permissions = (
("menu_proveedor", "Puede ver menu de proveedor"),
)
In formularios.py (forms):
class FormularioProveedor(SignupForm):
class Meta:
model = Proveedor
fields = '__all__'
def save(self, request, user):
user = super(FormularioProveedor, self).save(request)
user.sexo = self.cleaned_data['sexo']
user.tiene_empresa = self.cleaned_data['tiene_empresa']
user.save()
In views.py:
class ProveedorRegistroView(SignupView):
template_name = 'account/form_proveedor.html'
form_class = FormularioProveedor
redirect_field_name = 'proximo'
view_name = 'registroproveedor'
success_url = None
def get_context_data(self, **kwargs):
ret = super(ProveedorRegistroView, self).get_context_data(**kwargs)
ret.update(self.kwargs)
return ret
registroproveedor = ProveedorRegistroView.as_view()
urls.py in the package directory for testing:
url(r'registroproveedor', registroproveedor, name='registroproveedor')
Finally the template itself:
{% extends "account/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block title %}{% trans "Registro de Proveedor" %}{% endblock title %}
{% block content %}
<form id="signup_form" method="post" action="{% url 'registroproveedor' %}">
{% csrf_token %}
{{ form|crispy }}
</form>
{% endblock %}
I've only had new fields show up by pointing to my form in the settings, assigning ACCOUNT_SIGNUP_FORM_CLASS ... but that's not really what I need or want. I just want multiple registration forms, still able to utilize features provided by allauth and the template provided by cookiecutter-django. Right now, basing myself off of this template, I see too many things that might be wrong and any help would be appreciated. Thanks.