Wednesday, September 5, 2018

Re: Need help for saving JSON object into Django Model (class object)

Thanks , it works for me. 
there is minor changes request.data is not working, so I tried request.body
and then extracted value from dict.

Do you know any other way to it without using dict.
if yes please , help with same.

On Tuesday, September 4, 2018 at 8:29:58 PM UTC+5:30, pgopa...@gmail.com wrote:
# Please try to use this logic in your views.py file.
# first extract the data from the request 

question_text = request.data['question_text'] 
pub_date =  request.data['pub_date '] 

#Then store this data in your model.

Question.objects.create(question_text =question_text , pub_date = pub_date )

That's it. This will create an object in your data base with the data you extracted from the request. You can check in django admin panel.
Enjoy!


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4565c88c-c98f-4967-a512-02ef4e8cbca0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment