2012-01-02 2 views
0

나는 동시에 여기에 같은 제목과 카테고리를 wtih 내 양식 코드는 모든 메타의 우선 AddVideoViaLinkForm에 속해야 도움장고 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') 

답변

0

을하시기 바랍니다 것입니다 여러 VIDEO_ID (videolinks)를 추가하고 싶습니다. 이 클래스에서는 저장 기능을 추가하여 다음 작업을 수행 할 수 있습니다.

def save(self): 
    ids = self.cleaned_data['video_id'].split(",")# it depends what is your id separator 
    title = self.cleaned_data['title'] 
    for id in ids: 
     Videos.objects.create(video_id=id, title=title, ...)