个人资料照片django

时间:2016-03-27 18:56:21

标签: django-models django-forms user-profile

所以我有一个问题。我希望每个用户都有自己的个人资料图片,但是当我添加ImageField时,我的错误为app.profile_photo not be NULL

models.py

class Tutor(models.Model):
user = models.OneToOneField(User)
first_last_name = models.CharField(max_length = 50, validators=[RegexValidator(regex='^[a-zA-z ]*$', message = 'Please check your First or Last name', code = 'Invalid name')], null = False, blank = False)
birth_day = models.DateField()
profile_photo = models.ImageField(upload_to='img/',null=True,default='')
added = models.DateTimeField(auto_now_add = True, auto_now = False)
updated = models.DateTimeField(auto_now_add = False, auto_now = True)

forms.py

class RegistrationForm(ModelForm):
username = forms.CharField(label=(u'Username'),widget = forms.TextInput(attrs = {'placeholder': 'Username'}))
email = forms.EmailField(label=(u'Email'),widget = forms.TextInput(attrs = {'placeholder': 'Email'}))
password = forms.CharField(max_length=16, label=(u'Password'), 
    widget = forms.PasswordInput(attrs = {'placeholder': 'Password (min 8 chrct)'}, render_value = False),
    validators=[MinLengthValidator(8, message = 'Password must be at least 8 characters')])
repassword = forms.CharField(max_length=16, label=(u'Confirm your password (min 8 chrct)'), 
    widget = forms.PasswordInput(attrs = {'placeholder': 'Confirm password'}, render_value = False),
    validators=[MinLengthValidator(8, message = 'Password must be at least 8 characters')])

class Meta:
    model = Tutor
    exclude = ('user','added','updated','profile_photo')

0 个答案:

没有答案