0
我想添加多個VIDEO_ID(videolinks)同時wtih相同的標題和類別這裏是我的表單代碼,請做一些幫助的Django的ModelForm
class AddVideoViaLinkForm(forms.ModelForm):
title = forms.CharField(required=True,min_length=1,max_length=200)
video_id = forms.CharField(required=True,min_length=1,max_length=20)
category = forms.CharField(required=True,min_length=1,max_length=20)
description = forms.CharField(required=True,min_length=1,max_length=20)
def clean_title(self):
title = self.cleaned_data.get('title')
if title.strip()=='':
raise forms.ValidationError('Enter a Valid Title')
else:
return title
def clean_description(self):
description = self.cleaned_data.get('description')
if description.strip()=='':
raise forms.ValidationError('Enter a Valid Description')
else:
return description
class Meta:
model = Videos
fields = ('title','video_id','category','description')