回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>这是我的密码:</p>
<p>你知道吗型号.py你知道吗</p>
<pre><code>class Kitchen(models.Model):
kitchen_name = models.CharField(max_length = 100)
state = models.CharField(max_length = 40, )
city = models.CharField(max_length = 40)
def __str__(self):
return self.kitchen_name
class AssignAudit(models.Model):
kitchen = models.ForeignKey(Kitchen, on_delete = models.SET_NULL, null = True)
assigned_date = models.DateTimeField(default = timezone.now)
assigned_by = models.ForeignKey(User, on_delete = models.SET_NULL, null = True, related_name = 'assigned_audits')
class KitchenAudit(models.Model):
assign_audit = models.ForeignKey(AssignAudit, on_delete = models.SET_NULL, null = True)
question = models.ForeignKey(Question, on_delete = models.SET_NULL, null = True)
total_images = models.IntegerField(null = True, blank = True)
marks_scored = models.IntegerField(null=True,blank=True)
comment = models.CharField(max_length = 300, null = True, blank = True)
</code></pre>
<p>你知道吗序列化程序.py你知道吗</p>
<pre><code>class KitchenSerializer(serializers.ModelSerializer):
class Meta:
model = Kitchen
fields = '__all__'
class AssignAuditSerializer(serializers.ModelSerializer):
kitchen = KitchenSerializer()
class Meta:
model = AssignAudit
fields = '__all__'
def create(self, validated_data):
assign_audit = AssignAudit.objects.create(**validated_data)
questions = Question.objects.all()
for question in questions:
kitchen_audit = KitchenAudit.objects.create(question=question,assign_audit=assign_audit)
for images in range(question.no_of_images):
KitchenAuditImage.objects.create(kitchen_audit=kitchen_audit)
return assign_audit
</code></pre>
<p>你知道吗视图.py你知道吗</p>
<pre><code>class AssignAuditSerializerListCreate(ListCreateAPIView):
serializer_class = AssignAuditSerializer
queryset = AssignAudit.objects.all()
def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())
page = self.paginate_queryset(queryset)
if page is not None:
serializer = self.get_serializer(page, many=True)
return self.get_paginated_response(serializer.data)
serializer = self.get_serializer(queryset, many=True)
return Response({'audit_assign':serializer.data})
</code></pre>
<p>我想结合上面的两个表,使用django rest框架在一个API中显示它。GET方法很好用,但当我使用POST方法时,它意味着我必须提供厨房价值。你知道吗</p>
<pre><code>{
"kitchen": [
"This field is required."
]
}
</code></pre>