def create(self, validated_data):
employer = User.objects.get(id=self.context.get('employer'))
candidate = User.objects.get(id=self.context.get('candidate_id'))
report_details_id = ReportDetails.objects.filter(
id__in=self.context.get('report_details_id'))
(report_candidate, created) = ReportCandidate.objects.get_or_create(
reported_by=employer.id, candidate_id=candidate.id,report_details_id=report_details_id)
return report_candidate
這里的 report_details_id 是一個多欄位查詢。如何在 get_or_create 方法中應用其中的每個資料?
The QuerySet value for an exact lookup must be limited to one result using slicing.
我從上面的代碼中得到了這個錯誤。提前致謝。
uj5u.com熱心網友回復:
report_details_id包含一個物件串列,這就是您收到上述錯誤的原因。要解決這個問題,您只需要使用in運算子。
喜歡 :-
reported_by=employer.id, candidate_id=candidate.id,report_details_id__in=report_details_id)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/408286.html
標籤:
