Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def post_comment(request, interview_id, applicant_id):
- if request.POST:
- text = str(request.POST['add_comment'])
- interview = Interview.objects.get(id = interview_id)
- applicant = Applicant.objects.get(id = applicant_id)
- response = Response.objects.filter(interview = interview, applicant = applicant)
- date = datetime.datetime.now()
- comment = Comment(
- user = request.user,
- applicant = applicant,
- interview = interview,
- response = response,
- comment = text,
- created_at = date,
- )
- class Response(models.Model):
- video_guid = models.CharField(max_length=32)
- interview = models.ForeignKey(Interview)
- applicant = models.ForeignKey(Applicant)
- question = models.ForeignKey(Question)
- class Comment(models.Model):
- user = models.ForeignKey(User)
- applicant = models.ForeignKey(Applicant)
- interview = models.ForeignKey(Interview)
- response = models.ForeignKey(Response)
- comment = models.TextField(default='')
- created_at = models.DateTimeField(default=datetime.datetime.now())
- for i in response:
- Comment.objects.create(
- user = request.user,
- applicant = applicant,
- interview = interview,
- response = i,
- comment = text,
- created_at = date)
- c = Comment.objects.get(pk=1)
- c.response.interview # interview object
- # Get all the comments for where the interview objects primary key is 1
- c = Comment.objects.filter(response__interview__pk=1)
- r = Response.objects.get(pk=1)
- r.comment_set.all() # all comments for this response
Add Comment
Please, Sign In to add comment