exclude에 대한 공식 문서를 이해할 수 없습니다. 다음과 같이Django : 양식 저장 excelde 특정 필드
Set the exclude attribute of the ModelForm‘s inner Meta class to a list of fields to be excluded from the form.
For example:
class PartialAuthorForm(ModelForm):
class Meta:
model = Author
exclude = ['title']
Since the Author model has the 3 fields name, title and birth_date, this will result in the fields name and birth_date being present on the form.
나의 이해는 다음과 같습니다 ('뭔가'), '뭔가'필드가 프론트 엔드에 = 표시되지 않습니다 제외되는 한 세트 data.If 모든 양식을 저장합니다 저장 방법 양식을 장고 양식 저장 방법을 호출하는 동안 저장되지 않습니다.
하지만 내가 말하는 문서로 할 때 'something'필드이 여전히 표시됩니다. 무슨 문제입니까?
저장을하지 않고 프론트 엔드에 표시 할 수있는 유효성 검사 양식에 일부 필드를 추가하고 싶습니다.이 필요성에 관해서는 아무 것도 발견하지 못했습니다.
**update**
내 코드 :
class ProfileForm(Html5Mixin, forms.ModelForm):
password1 = forms.CharField(label=_("Password"),
widget=forms.PasswordInput(render_value=False))
password2 = forms.CharField(label=_("Password (again)"),
widget=forms.PasswordInput(render_value=False))
captcha_text = forms.CharField(label=_("captcha"),
widget=forms.TextInput())
captcha_detext = forms.CharField(
widget=forms.HiddenInput())
class Meta:
model = User
fields = ("email", "username")
exclude = ['captcha_text']
def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
..........
def clean_username(self):
.....
def clean_password2(self):
....
def save(self, *args, **kwargs):
"""
Create the new user. If no username is supplied (may be hidden
via ``ACCOUNTS_PROFILE_FORM_EXCLUDE_FIELDS`` or
``ACCOUNTS_NO_USERNAME``), we generate a unique username, so
that if profile pages are enabled, we still have something to
use as the profile's slug.
"""
..............
def get_profile_fields_form(self):
return ProfileFieldsForm
경우을 제외에만 너무 exclude = ['captcha_text']
이 작동하지 않을 것입니다, 클래스 메타에 정의 모델에 영향을 줍니까?
따라서 save 메소드는 ** class Meta **에 정의 된'model'을 저장하는 데에만 사용되며 extra_field는 저장되지 않습니다. – Mithril
extra_field가 모델 자체에 없으므로 어디에서 예상합니까? 저장하려면 extra_field를 사용 하시겠습니까? – Sudipta
고마워요! 이제 알 겠어요. 대형 장고 프로젝트에서 약간의 수정을하는 것은 정말 어려운 방법입니다 ... – Mithril