i want to add 'Acc_type' field in signup form
for that i create one app called 'signup'
signup/models.py
from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _
class UserProfile(models.Model):
ACC_CHOICES = (
('Individual', 'Individual'),
('Business', 'Business'),
)
user = models.OneToOneField(User, related_name='profile')
acc_type = models.CharField(max_length=20, verbose_name =_('Account_Type'), choices=ACC_CHOICES),
def __unicode__(self):
return self.user.username
signup/forms.py
from allauth.account.forms import SignupForm
from django import forms
from .models import UserProfile
class SignupForm(SignupForm):
class Meta:
model = UserProfile
acc_type = forms.CharField(max_length=20, label='Account_Type')
def save(self, user):
user.acc_type = self.cleaned_data['acc_type']
user.save()
signup.py/views.py
from django.shortcuts import render
from django.template import RequestContext
from django.shortcuts import render_to_response
from .forms import SignupForm
def index(request):
#form = MySignupForm()
form = SignupForm()
return render_to_response("index.html", locals(),
context_instance=RequestContext(request))
in my setting.py
ACCOUNT_SIGNUP_FORM_CLASS = 'signup.forms.SignupForm'
in my project/url.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf.urls.i18n import i18n_patterns
urlpatterns = i18n_patterns('',
url(r'^$', 'register.views.home', name='home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('allauth.urls')),
)
it still give error
"ImproperlyConfigured: Error importing form class signup.forms: "cannot import name SignupForm"
"
so how can i solve that
pls help,Thanks in advance!!!
Simply let ACCOUNT_SIGNUP_FORM_CLASS point to class that inherits from plain django.forms.Form -- do not inherit from a User ModelForm, or an allauth SignupForm.
I try with normal form in forms.py
signup/forms.py
from django import forms
from .models import UserProfile
class SignupForm(forms.Form):
class Meta:
model = UserProfile
acc_type = forms.CharField(max_length=20, label='Account_Type')
def signup(self, request, user):
user.acc_type = self.cleaned_data['acc_type']
user.save()
is still give following error ,
' 'The custom signup form must implement a "signup" method')
ImproperlyConfigured: The custom signup form must implement a "signup" method'
i already use sigup methon in forms
pls help!!!how can i solve this error.
Given that you are using a normal form, you can drop the class Meta. As for the signup, you should offer a def signup(self, request, user) method. It looks like you have done that, but given the way your example is laid out I cannot tell if the def signup is on module or class level?
ok but can you pls suggest me how we add this 'acc_type' field in django user table
pls help,thanks in advance!!!
Thanks for reply!!!
Most helpful comment
Have a look here: http://stackoverflow.com/questions/12303478/how-to-customize-user-profile-when-using-django-allauth