Django saving json value to database/model : <p>Im new to django and im trying to save <strong>json to database</strong>. The problem is that im able to get data the data in my views but not sure <strong>how to save it in database</strong>. Im trying to save the <strong>comments</strong></p>

<p>models.py</p>

<pre><code>class Post(models.Model):
    title=models.CharField(max_length=200)
    description=models.TextField(max_length=10000)
    pub_date=models.DateTimeField(auto_now_add=True)
    slug = models.SlugField(max_length=40, unique=True)

    def __unicode__(self):
        return self.title


class Comment(models.Model):
    title=models.ForeignKey(Post)
    comments=models.CharField(max_length=200)

    def __unicode__(self):
        return '%s' % (self.title)
</code></pre>

<p>serializer.py</p>

<pre><code>class CommentSerializer(serializers.ModelSerializer):
    id = serializers.CharField(source="title.id", read_only=True)
    title = serializers.CharField(source="title.title", read_only=True)

class Meta:
    model = Comment
    fields = ('id','title','comments')


class PostSerializer(serializers.ModelSerializer):

    class Meta:
        model = Post
        fields = ('id','title','description','pub_date')
</code></pre>

<p>Please help me saving the data from views to database</p>

<p>view.py</p>

<pre><code>def add_comments(request):
    if 'application/x-www-form-urlencoded' in request.META['CONTENT_TYPE']:
        print 'hi'
        data = json.loads(request.body)
        comment = data.get('comment', None)
        id = data.get('id', None)
        title = data.get('title', None) 
        ....................# not sure how to save to database
       pass
</code></pre>

<p>Thanks in advance........Please let me know if there is any better way to do it...</p>
