Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. def post_comment(request, interview_id, applicant_id):
  2. if request.POST:
  3. text = str(request.POST['add_comment'])
  4. interview = Interview.objects.get(id = interview_id)
  5. applicant = Applicant.objects.get(id = applicant_id)
  6. response = Response.objects.filter(interview = interview, applicant = applicant)
  7. date = datetime.datetime.now()
  8. comment = Comment(
  9. user = request.user,
  10. applicant = applicant,
  11. interview = interview,
  12. response = response,
  13. comment = text,
  14. created_at = date,
  15. )
  16.  
  17. class Response(models.Model):
  18. video_guid = models.CharField(max_length=32)
  19. interview = models.ForeignKey(Interview)
  20. applicant = models.ForeignKey(Applicant)
  21. question = models.ForeignKey(Question)
  22.  
  23.  
  24. class Comment(models.Model):
  25. user = models.ForeignKey(User)
  26. applicant = models.ForeignKey(Applicant)
  27. interview = models.ForeignKey(Interview)
  28. response = models.ForeignKey(Response)
  29. comment = models.TextField(default='')
  30. created_at = models.DateTimeField(default=datetime.datetime.now())
  31.  
  32. for i in response:
  33. Comment.objects.create(
  34. user = request.user,
  35. applicant = applicant,
  36. interview = interview,
  37. response = i,
  38. comment = text,
  39. created_at = date)
  40.  
  41. c = Comment.objects.get(pk=1)
  42. c.response.interview # interview object
  43.  
  44. # Get all the comments for where the interview objects primary key is 1
  45. c = Comment.objects.filter(response__interview__pk=1)
  46.  
  47. r = Response.objects.get(pk=1)
  48. r.comment_set.all() # all comments for this response
Add Comment
Please, Sign In to add comment