def mutate(cls, root, info, project_id, blog): user = info.context.user if (user.is_authenticated): project = Project.objects.get(pk=project_id) author = User.objects.get(pk=user.id) if (author in project.members.all() or author in project.moderators.all() or author == project.admin): project_blog = Blog(author=author, title=blog.title, is_project_blog=True) if blog.data is not None: project_blog.data = blog.data if blog.tags is not None: project_blog.tags = blog.tags if blog.more_info is not None: project_blog.more_info = blog.more_info project_blog.save() project.blogs.add(project_blog) project.save() return AddProjectBlogMutation(blog=project_blog) raise Exception( "You don't have permissions to perform this action") raise Exception("You have to be logged in to access api")