Reputation: 149
I have a list like this form.
[{'XPos': {'$': 128.604314661},
'YPos': {'$': 35.8662354972},
'clCd': {'$': 1},
'drTotCnt': {'$': 545},
'estbDd': {'$': 19100907}
},
{'XPos': {'$': 128.096026987},
'YPos': {'$': 35.1753899647},
'clCd': {'$': 1},
'drTotCnt': {'$': 326},
},
{'XPos': {'$': 127.050741243},
'YPos': {'$': 37.5937747637},
'clCd': {'$': 1},
'drTotCnt': {'$': 412},
'estbDd': {'$': 19711005}
},
{'XPos': {'$': 128.582521394},
'YPos': {'$': 35.8701796577},
'clCd': {'$': 1},
'drTotCnt': {'$': 427}
},
{'XPos': {'$': 126.884639554},
'YPos': {'$': 37.4911811753},
'clCd': {'$': 1},
'drTotCnt': {'$': 498},
'estbDd': {'$': 19830831}
},
{'XPos': {'$': 126.824997324},
'YPos': {'$': 37.3188581763},
'clCd': {'$': 1},
'drTotCnt': {'$': 281},
'estbDd': {'$': 19860101},
}]
and using django-rest-framework deserializer, i want to insert that data into my database.
BUT, i have some problems.
How can i filter that datas and input to my database?
http://www.django-rest-framework.org/api-guide/serializers/
i referenced that site.
Upvotes: 0
Views: 37
Reputation: 2106
In your case, you can just create a new dictionary and save that to the database:
# assuming your list is calles 'my_list'
for item in my_list:
if hasattr(item, 'estbDd'):
my_model = MyModel()
my_model.XPos = item['XPos']['$']
my_model.YPos = item['YPos']['$']
my_model.estbDb = item['estbDb']['$']
my_model.save()
Does that solve your question?
Upvotes: 1