Esempio n. 1
0
 def form_valid(self, form):
     new_blog = Blog(
         author=self.request.user.username,
         content="Image",
         posted_on=datetime.now(),
         post_type=PostChoice.Pic,
         pic=form.cleaned_data["pic"],
     )
     new_blog.save()
     return super(PicView, self).form_valid(form)
Esempio n. 2
0
 def form_valid(self, form):
     data = form.cleaned_data
     post_type = PostChoice.Status
     if data["post_type"] == PostChoice.Pic:
         pass
     elif data["post_type"] == PostChoice.Blog:
         post_type = PostChoice.Blog
     new_blog = Blog(
         author=self.request.user,
         title=data["title"],
         content=data["content"],
         post_type=post_type,
         status=StatusChoice.Posted,
     )
     new_blog.save()
     tags = re.findall(r"[\w']+", data["tags"])
     temp_tags = []
     for tag in tags:
         t = Tag.objects.get_or_create(name=tag)
         temp_tags.append(t[0])
     new_blog.tags = temp_tags
     new_blog.save()
     return super(ScribbleView, self).form_valid(form)