【发布时间】:2020-06-29 16:46:03
【问题描述】:
我正在使用 Django REST 框架
我的响应低于 JSON 当前 JSON [ { “身份证”:1, “名字”:“拉克什”, “姓氏”:“Maini” }, { “身份证”:2, “名字”:“塔伦”, “姓氏”:“阿罗拉” } ]
预期的 JSON
{
“雇员”: [
“拉克什”,
“塔伦”,
]
}
firstname = models.CharField(max_length=50)
laststname = models.CharField(max_length=50)
emp_id = models.IntegerField
def __str__(self):
return self.firstname
class Meta:
model = employees
fields= "__all__"
# This method will return the data of emploies
def get(self, request):
employee = employees.objects.all()
serializer = employeesSerializer(employee, many=True)
return Response(serializer.data)
【问题讨论】:
标签: python django-models django-rest-framework django-views