我的updateView创建一个新帖子,而不是更新旧帖子

时间:2020-07-10 11:14:06

标签: python django django-views

我的updateView创建一个新帖子,而不是更新旧帖子。我想更新我的帖子,但是当我去更新表单时,它会创建一个全新的帖子

views.py

def edit_task(request, post_id):
    post = Post.objects.get(id=post_id)
    form = TaskForm(instance=post)
    if request.method == 'POST':
        print(request.POST)
        form = TaskForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('task')
    context = {'form': form}
    return render(request, 'List/add_task.html', context)

1 个答案:

答案 0 :(得分:0)

您需要为GET请求和POST请求传递实例:

select * from 
(
select t.*, max(grab_time) over (partition by id) as mx
from your_table where ended = false
)
where grab_time = mx