Hi,
I'm trying to create embedded documents in mongodb using django. I'm facing 
this error when I tried to insert a post in database.
"ValueError at /post/Value: None must be instance of Model: <class 
'django.db.models.base.Model'>"
Here is my code.
models.py
from djongo import models


# Schema for comments collection which include in belonging post
class Comments(models.Model):
username = models.CharField(max_length=25, blank=False)
comment = models.TextField()
time_stamp = models.DateTimeField(auto_now_add=True)


# Schema for post collection
class Post(models.Model):
username = models.CharField(max_length=25, blank=False)
title = models.CharField(max_length=100, blank=False)
post = models.TextField()
time_stamp = models.DateTimeField(auto_now_add=True)
comments = models.EmbeddedModelField('Comments')

# allows to use all functionality of django orm
objects = models.DjongoManager()

def __str__(self):
return self.post

serializers.py

from rest_framework import serializers
from models import Post, Comments


class PostSerializer(serializers.ModelSerializer):
class Meta:
model = Post
fields = ('id', 'username', 'title', 'post', 'time_stamp')


class CommentsSerializer(serializers.ModelSerializer):
class Meta:
model = Comments
fields = '__all__'

views.py
from rest_framework_mongoengine import generics
from serializers import PostSerializer, CommentsSerializer
from models import Post, Comments


class PostAPIView(generics.CreateAPIView):
lookup_field = 'id'
serializer_class = PostSerializer

def get_queryset(self):
return Post.__objects.all()


class CommentsAPIView(generics.CreateAPIView):
lookup_field = 'id'
serializer_class = CommentsSerializer

def get_queryset(self):
return Comments.__objects.all()

what is the problem with the code? Is this right method to create embedded 
documents in mongodb?
I used python3.6.4, django2.1, djongo1.2.29 and other libraries like 
pymongo and mongoengine

-- 
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+unsubscr...@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/affc5cc1-65bf-4e6c-88d1-de6a745e3527%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to