好奇他們的差異。例如:django形式的meta和property的區別是什麼?
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
GENDER_CHOICES = (
('M', '남'),
('F', '여'),
)
class MyUserCreationForm(UserCreationForm):
email = forms.EmailField(required=True)
birth = forms.DateField(widget=forms.SelectDateWidget(
years=range(1970, 2015)), required=True)
gender = forms.ChoiceField(choices=GENDER_CHOICES, initial='M')
class Meta:
model = User
fields = ('username', 'birth', 'email',
'gender', 'password1', 'password2')
def save(self, commit=True):
user = super(MyUserCreationForm, self).save(commit=False)
user.email = self.cleaned_data['email']
user.birthday = self.cleaned_data['birth']
if commit:
user.save()
return user
它定義email
,birth
,gender
爲形式的性質,並且它也有在Class Meta
fields
。我想清楚地瞭解他們的區別。提前致謝。