表格中的清洁不起作用

时间:2014-10-04 15:11:59

标签: python django

我正在尝试创建用户的用户名lowercase。但不知怎的,它不起作用。我只是看不到错误......为什么它不起作用?

型号:

class UserProfile(models.Model):
    # This line is required. Links UserProfile to a User model instance.
    user = models.OneToOneField(User)

    # The additional attributes we wish to include.
    website = models.URLField()

    # Override the __unicode__() method to return out something meaningful!
    def __unicode__(self):
        return self.user.username

形式:

class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput())

    class Meta:
        model = User
        fields = ('username', 'email', 'password')

    def clean_username(self):
        username = self.cleaned_data['username'].lower()
        return username

0 个答案:

没有答案