utils_19.py 871 B

1234567891011121314151617181920
  1. def test_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 = 14
  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 = 14
  17. file_save.file = request.FILES.get("file")
  18. file_save.save()
  19. return redirect('test_list')
  20. return render(request, 'test_write.html')