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?
m = Configuration.objects.get(id=1) # you need to get single object here
serializer = ConfigurationSerializer(m) # remove many = True
Simply remove the many=True from the serializer instantiation:
serializer = ConfigurationSerializer(m)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With