3-09 게시물 수정 & 삭제 기능 추가하기, 질문 수정 함수 추가하기 question.author = request.user 질문

질문 수정 기능 추가하기의 [3] 질문 수정 함수 추가하기 부분에서 질문 있습니다.
question.author = request.user 에서 궁금한 게 있습니다.
question = get_object_or_404(Question, pk=question_id)로 수정할 Question모델 객체를 가지고 왔는데
이미 question.author에는 모델 객체를 생성한 유저(수정하는 유저)가 저장되어 있는 상태아닌가요?

수정한 후에 다시한번 아래의 코드를 사용해서 현재 유저가 Question모델 객체의 author로 할당되는데
이 수정할때 다시 한번 저장하는 이유가 궁금합니다.
이미 1. 탬플릿에서 if request.user == question.author 로 확인 2. view에서@login_required(login_url="common:login")로 재차 확인했는데
다시 한번 author부분을 할당하고 저장하는 이유는 뭔가요?

<질문코드>

question.author = request.user

<해당 예제코드>

def question_modify(request, question_id):
    """
    pybo 질문수정
    """
    question = get_object_or_404(Question, pk=question_id)
    if request.user != question.author:
        messages.error(request, '수정권한이 없습니다')
        return redirect('pybo:detail', question_id=question.id)

    if request.method == "POST":
        form = QuestionForm(request.POST, instance=question)
        if form.is_valid():
            question = form.save(commit=False)
            question.author = request.user   #다시 저장하는 이유?
            question.modify_date = timezone.now()  # 수정일시 저장
            question.save()
            return redirect('pybo:detail', question_id=question.id)
    else:
        form = QuestionForm(instance=question)
    context = {'form': form}
    return render(request, 'pybo/question_form.html', context)

HJ 347

2021년 7월 18일 11:43 오후

넵. 불필요한 코드로 빼시면 됩니다. - 박응용님, 2021년 7월 19일 12:00 오전 추천 , 대댓글
@박응용님 답변 감사합니다! - HJ님, 2021년 7월 19일 12:04 오후 추천 , 대댓글
목록으로