次のエラーが表示されます: Cannot assign "[<Response: Response object>, <Response: Response object>]": "Comment.response" must be a "Response" instance
。応募者と面接 ID を照合して、インスタンスに応答を割り当てるにはどうすればよいですか? また、objects.filter() からのすべての可能な結果のうち、最初の応答のみが必要です。
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())
私はDjangoを初めて使用しています:(どんな助けも大歓迎です!