You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.8 KiB

from django import forms
from movie.model import User,Movie_rating
class RegisterForm(forms.ModelForm):
password_repeat=forms.CharField(max_length=256)
def get_errors(self):
errors=self.errors.get_json_data()
errors_lst=[]
for messages in errors.values():
for message_dict in messages:
for key,message in message_dict.items():
if key=='messasge':
errors_lst.append(message)
return errors_lst
def clean(self):
cleaned_data=super(RegisterForm,self).clean()
pwd=cleaned_data.get('password')
password_repeat=cleaned_data.get('password_repeat')
if pwd!=password_repeat:
raise forms.ValidationError(message='两次密码输入不一致!')
return cleaned_data
class Meta:
model=User
fields=['name','password','email']
class LoginForm(forms.ModelForm):
name=forms.CharField(max_length=128)
remember=forms.IntegerField(required=False)
class Mate:
model=User
fields=['password']
def get_errors(self):
errors=self.errors.get_json_data()
errors_lst=[]
for messages in errors.values():
for message_dict in messages:
for key,message in message_dict.items():
if key=='messasge':
errors_lst.append(message)
return errors_lst
class CommentForm(forms.ModelForm):
def clean(self):
cleaned_data=super(CommentForm,self).clean()
score=cleaned_data.get('score')
if score<0 or score>5:
raise forms.ValidationError(message='评分不能为空!')
else:
return cleaned_data
class Meta:
model=Movie_rating
fields=['score','comment']