class VideoEnForm(forms.Form): title = forms.CharField(required=True, error_messages=ERROR_MESSAGES) text = forms.CharField(required=True, error_messages=ERROR_MESSAGES) youtube_id = forms.CharField(required=True, error_messages=ERROR_MESSAGES) published_at = forms.DateTimeField(required=True, error_messages=ERROR_MESSAGES) introductions = forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, choices=lambda: [(v.id, v.id) for v in IntroductionEn.get_all()], error_messages=ERROR_MESSAGES) topics = forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, choices=lambda: [(v.id, v.id) for v in TopicEn.get_all()], error_messages=ERROR_MESSAGES) categories = forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, choices=lambda: [(v.id, v.id) for v in Category.get_all()], error_messages=ERROR_MESSAGES) videos = forms.MultipleChoiceField( required=False, widget=forms.CheckboxSelectMultiple, choices=lambda: [(v.id, v.id) for v in VideoEn.get_all()], error_messages=ERROR_MESSAGES)
def remove_video_self(cls, video_id): all_topic_ids = [v.id for v in TopicEn.get_all()] try: video = cls.objects.get(id=video_id) for v in all_topic_ids: video.video.remove(v) except: pass
def add_topic(cls, video_id, topic_ids): topic_ids = list(map(int, topic_ids)) all_topic_ids = [v.id for v in TopicEn.get_all()] try: video = cls.objects.get(id=video_id) for v in all_topic_ids: if v in topic_ids: try: video.topic.add(v) except: pass else: video.topic.remove(v) except: pass