Advertisement
Guest User

Untitled

a guest
Mar 31st, 2021
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. ####views.py
  2. def pg_session_addedcost(request, pk = 1):
  3. user = request.user
  4.  
  5. if not user.is_authenticated:
  6. return redirect('autherror')
  7.  
  8. curSession = Session.objects.get(id = pk)
  9.  
  10. if request.method == "POST":
  11. newAddedCostForm = AddedCostForm(request.POST)
  12. if newAddedCostForm.is_valid():
  13. newAddedCost = AddedCost(
  14. comment=newAddedCostForm.cleaned_data['comment'],
  15. session=curSession,
  16. image=newAddedCostForm.cleaned_data['image'],
  17. cost=newAddedCostForm.cleaned_data['cost'],
  18. )
  19. newAddedCost.save()
  20. else:
  21. print(newAddedCostForm.errors)
  22.  
  23. content = {
  24. 'user':user,
  25. 'session':curSession,
  26. 'form':AddedCostForm(),
  27. 'addedcost':AddedCost.objects.filter(session = curSession),
  28. }
  29.  
  30. return render(request, 'staffapp/pg_addedcost.html',content)
  31.  
  32.  
  33. ###HTML
  34.  
  35. {% load widget_tweaks %}
  36. <form method="POST">
  37. {% csrf_token %}
  38.  
  39. {% render_field form.image %}<br>
  40. {% render_field form.cost %}<br>
  41. {% render_field form.comment %}<br>
  42.  
  43. <button type="submit">
  44. Добавить
  45. </button>
  46. </form>
  47.  
  48. ###Текст ошибки
  49. <ul class="errorlist"><li>image<ul class="errorlist"><li>Обязательное поле.</li></ul></li></ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement