python - Use JSON to create Model objects - Django -


i have external url containing json.

so question is: how save json data django admin page if created following model matches keys of json?

from django.db import models  class person(models.model):      name = models.charfield(max_length=254)     image_url = models.imagefield(blank=true)     title = models.charfield(max_length=254)     bio = models.charfield(max_length=20000)     vote = models.integerfield() 

my goal able create voting app lets vote each individual person defined json.

here longer version of question: https://stackoverflow.com/questions/46149309/create-object-models-from-external-json-link-django

if understand question correctly can use model serializers end.

class personserializer(serializers.modelserializer):     class meta:         model = person 

and can use personserializer populate model person_json objects (in case in array of json objects) rest api.

personsaver = personserializer(data=person_json, many=true) if personsaver.is_valid():     personsaver.save() 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -