def confirmemail(request,token):
user = Users.objects.get(email_token = token)
if user:
user.email_token = ''
user.email_token_expiry = ''
user.email_verified = 1
user.active = 1
user.save()
return render_to_response('confirmemail.html', {'user': user}, context_instance=RequestContext(request))
Я получаю ошибку:
ValidationError at /confirmemail/mw054b7el2/
[u'Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format.']
Request Method: GET
Request URL: http://127.0.0.1:8000/confirmemail/mw054b7el2/
Django Version: 1.3.1
Exception Type: ValidationError
Exception Value:
[u'Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format.']
Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/models/fields/__init__.py in to_python, line 710
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/user1/djangoblog',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/pymodules/python2.6/gtk-2.0']
email_token_expiry
- это поле datetime
в таблице mysql.
Как я могу установить email_token_expiry
в ноль или в пустое или в правую форму ноль / 0 / пустое время / дата?
Буду очень признателен, если кто-нибудь поможет мне решить эту проблему.
models.py:
class Users(models.Model):
username = models.CharField(max_length=255,unique=True)
slug = models.CharField(max_length=255, default='0')
password = models.CharField(max_length=300)
password_token = models.CharField(max_length=300, default='0')
email = models.CharField(max_length=255, unique=True)
email_verified = models.BooleanField(default=False)
email_token = models.CharField(max_length=255)
email_token_expiry = models.DateTimeField()
tos = models.BooleanField(default=False)
active = models.BooleanField(default=False)
last_login = models.DateTimeField(auto_now_add=True)
last_action = models.DateTimeField(auto_now_add=True)
is_admin = models.BooleanField(default=False)
role = models.CharField(max_length=255, default='0')
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return self.username
class UsersModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(UsersModelForm, self).__init__(*args, **kwargs)
self.fields.keyOrder = ['username', 'email', 'password', 'passwordrepeat']
passwordrepeat = forms.CharField(max_length=300, widget=forms.PasswordInput, label=u'Repeat Password')
class Meta:
model = Users
fields = ('username', 'password', 'passwordrepeat', 'email')
widgets = {
'password' : forms.PasswordInput(),
}
def clean(self):
cleaned_data = self.cleaned_data
password = cleaned_data.get("password")
passwordrepeat = cleaned_data.get("passwordrepeat")
if password != passwordrepeat:
raise forms.ValidationError("Passwords must match.")
return cleaned_data