ユーザーを登録するためにフォームに入力するたびに、last_loginとdate_joinedが自動的に設定される必要があるため、プロセスが停止します。または、通常どおりサインアップできるようにどこに追加できますか?Views.py
import datetime
@csrf_exempt
def EmployerRegistration(request):
print 'before'
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method == 'POST':
form = SignUpForm(request.POST)
print form
print"then"
print form.errors
if form.is_valid():
print 'hello'
employer =Employer.objects.create(username=form.cleaned_data["username"],password= form.cleaned_data['password'],first_name=form.cleaned_data['first_name'],last_name=form.cleaned_data['last_name'],email=form.cleaned_data['email'],address=form.cleaned_data['address'],mobile=form.cleaned_data['mobile'])
employer.save()
return HttpResponseRedirect('/login/')
else:
print 'notvalid'
return render_to_response('Sign_up_Employer.html',{'form':form}, context_instance=RequestContext(request))
#return render_to_response('/lol/',{'form':form}, context_instance=RequestContext(request))
last_login
else:
#user is not submitting show them the registeration form
print 'not post'
form= SignUpForm()
context = {'form':form}
return render_to_response('Sign_up_Employer.html',context,context_instance=RequestContext(request))
form.py
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django import forms
from django.forms import ModelForm
from shoghlanah.models import *
import datetime
class SignUpForm(ModelForm):
username = forms.CharField(label=(u'Username'))
first_name = forms.CharField(label=(u'First name'))
last_name = forms.CharField(label=(u'Last name'))
address = forms.CharField(label=(u'Address'))
email = forms.EmailField(label=(u'Email Address'))
password = forms.CharField(label=(u'Password'),widget=forms.PasswordInput(render_value=False))
password1 = forms.CharField(label=(u'Verify Password'),widget=forms.PasswordInput(render_value=False))
mobile = forms.IntegerField(label=(u'Mobile'))
## is it valid to put the here??
last_login =datetime.datetime.now()
date_joined =datetime.datetime.now()
class Meta:
model = Employer
## check whats Exclude !!!!
exclude = ('user',)
def clean_username(self):
username = self.cleaned_data['username']
try:
User.objects.get(username=username)
raise forms.ValidationError("That username already exists.Please select another")
except User.DoesNotExist:
return username