I'm able to successfully serialize my model objects using django serializers, but want a dictionary, not a list with a dictionary in it. I naturally googled and read other Stack Overflow answers, but I don't understand how to implement the solutions. This is a basic question, but I'm learning.
I'm trying to send models to Keen.io, and when using Django's serializer, am getting a list with objects, which yields the following error:
{u'message': u'An event should be a JSON object of properties.', u'error_code': u'InvalidEventError'}
So I'm trying to get a proper JSON object.
Here's my model:
class CustomModel(models.Model):
name = models.CharField(max_length = 50)
location = models.CharField(max_length = 50)
birthday = models.DateField()
I've been looking at some of the built in Django options as described in this post, but I don't understand how to use them, and I'd like to. So if some folks could address a couple of questions:
The function to_dict() seems to be used only for instances? Can it be used for a full Model? When I try, I get an Attribute error. How can I use it to render my model as a dict? Will that get me what I need?