创建前选中空白

时间:2019-06-11 19:14:08

标签: django django-rest-framework

由于某种原因,即使我没有所有必填字段,POST方法也允许我创建Telefono_paciente。

# Create a new telefono_paciente
def post(self, request):
    serializer = Telefono_pacienteSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)



class Telefono_paciente(models.Model): 
    tipo = models.CharField(max_length=3,null=True, blank=False, choices=PHONE_CHOICES)
    Paciente = models.ForeignKey(Paciente, null=True, blank=False, on_delete=models.CASCADE)

def __str__(self):
    return '%s %s %s' % (self.tipo, self.lada, self.telefono)

class Meta:
    verbose_name_plural = "Pacientes - Telefonos"

1 个答案:

答案 0 :(得分:0)

两个模型的字段中有null=True,因此不需要。