In my django application with database engine djongo, I'm trying to return a JSON response by retrieving from my database. But, I'm receiving JSON array instead of JSON object. Currently, there is only one record in my database. Please see the code below.
model.py
class bloodDonors(models.Model):
location=models.CharField(max_length=20)
name=models.CharField(max_length=20)
phone=models.IntegerField()
address=models.TextField()
bloodGroup=models.CharField(max_length=5)
type=models.CharField(max_length=20)
def __str__(self):
return self.name
views.py
class bloodDonersView(viewsets.ModelViewSet):
queryset = bloodDonors.objects.all()
serializer_class = bloodDonorsSerializer
JSON Reponse:
[
{
"id": 3,
"location": "Delhi",
"name": "Tony",
"phone": 888,
"address": "South street",
"bloodGroup": "B+",
"type": "blood-donation"
}
]
But, actually I needed the response as given below:
{
"id": 3,
"location": "Delhi",
"name": "Tony",
"phone": 888,
"address": "South street",
"bloodGroup": "B+",
"type": "blood-donation"
}
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5656271c-fe21-4933-ad3f-9dc7505a56c1%40googlegroups.com.
No comments:
Post a Comment