def create_post(request): if request.user.is_staff: form = PostsForm(request.POST or None, request.FILES or None) if form.is_valid(): form.save() return redirect('/index') return render(request, 'posts/create_post.html', {'form': form}) return redirect('/error/')
def edit_post(request, post_id): if request.user.is_staff: post = Posts.objects.get(id=post_id) form = PostsForm(request.POST or None, request.FILES or None, instance=post) if form.is_valid(): form.save() return redirect('/index') return render(request, 'posts/create_post.html', {'form': form}) return redirect('/error/')