utils_18.py 875 B

1234567891011121314151617181920
  1. def notice_write(request):
  2. if request.method == 'POST':
  3. form = ContentForm(request.POST)
  4. form_file = FileForm(request.POST, request.FILES)
  5. if form.is_valid():
  6. question = form.save(commit=False)
  7. question.author = request.user
  8. question.create_date = timezone.now()
  9. question.boardname_id = 7
  10. question.save()
  11. if form_file.is_valid():
  12. form_file = FileForm(request.POST, request.FILES)
  13. file_save = form_file.save(commit=False)
  14. file_save.author = request.user
  15. file_save.postcontent = question
  16. file_save.boardname_id = 7
  17. file_save.file = request.FILES.get("file")
  18. file_save.save()
  19. return redirect('notice_view')
  20. return render(request, 'notice_write.html')