I have a Table "Configuration".
class Configuration(models.Model):
inventory_check = models.BooleanField(default=False)
refund = models.BooleanField(default=False)
record_seat_number = models.BooleanField(default=False)
base_url = models.URLField()
This table will have a single entry. Below is the serializer :
class ConfigurationSerializer(serializers.ModelSerializer):
class Meta:
model = Configuration
fields = '__all__'
I am using rest framework for the API. Below is the Views.py
@api_view(['GET'])
def get_configuration(request):
m = Configuration.objects.all()
serializer = ConfigurationSerializer(m, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
This works perfectly. But the problem is this would return object inside array.
[
{
"id": 1,
"inventory_check": false,
"refund": true,
"record_seat_number": false,
"base_url": "http://localhost:8000/"
}
]
All I want is to send only the object without array. How to achieve this?
Configuration.objects.all()you get a QuerySet. It converts into array in JSON. If you explicitly need only a single object, you should rethink your design. For exampleConfiguration.objects.get(pk=1)will return a single object, if available.