def post_g(request, blog_id): if request.method == 'GET': u = get_user(request) if u is None: return JsonResponse({'status': -1, 'message': 'invalid token'}) iddd = request.GET.get('id') p = Post.objects.filter(post_id=iddd).first() post = { 'datetime': p.time, 'id': p.post_id, 'title': p.title, 'summary': p.summary, 'text': p.text } res = {'status': 1, 'post': post} return JsonResponse(res) if request.method == 'POST': f = Post_f(request.POST) if f.is_valid(): t = f.cleaned_data['text'] title = f.cleaned_data["t"] s = f.cleaned_data["s"] blog = Super_b.objects.filter(blog_id=blog_id).first() if blog is not None: post = Post.create(blog, title, s, t) post.save() return JsonResponse({ 'status': 1, 'message': 'Successfully Added The Post' }) else: print("else")
def postg(request, bid): if request.method == 'GET': id = get_user(request) if id is None: return JsonResponse({'status': -1, 'message': 'invalid token'}) pid = request.GET.get('id') p = Post.objects.filter(post_id=pid).first() post = {'datetime': p.time, 'id': p.post_id, 'title': p.title, 'summary': p.summary, 'text': p.text} res = {'status': 1, 'post': post} return JsonResponse(res) if request.method == 'POST': form = AddPostForm(request.POST) if form.is_valid(): text = form.cleaned_data['text'] title = form.cleaned_data['title'] summary = form.cleaned_data['summary'] blog = Blog.objects.filter(blog_id=bid).first() if blog is not None: post = Post.create(blog, title, summary, text) post.save() return JsonResponse({'status': 1, 'message': 'Successfully Added The Post'})