import proper package you were importing "djongo" it should be "django".
On Sat, Jan 26, 2019 at 8:13 PM <team.alphav3@gmail.com> wrote:
This usually happens when you have added and EmbeddedModel and not passing any value to that field while creation.--
Hope this helps.
On Sunday, 19 August 2018 19:32:49 UTC+5:30, Sagar wrote: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.pyfrom djongo import models# Schema for comments collection which include in belonging postclass 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 collectionclass 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 ormobjects = models.DjongoManager()def __str__(self):return self.post
serializers.pyfrom rest_framework import serializersfrom models import Post, Commentsclass PostSerializer(serializers.ModelSerializer):class Meta:model = Postfields = ('id', 'username', 'title', 'post', 'time_stamp')class CommentsSerializer(serializers.ModelSerializer):class Meta:model = Commentsfields = '__all__'
views.pyfrom rest_framework_mongoengine import genericsfrom serializers import PostSerializer, CommentsSerializerfrom models import Post, Commentsclass PostAPIView(generics.CreateAPIView):lookup_field = 'id'serializer_class = PostSerializerdef get_queryset(self):return Post.__objects.all()class CommentsAPIView(generics.CreateAPIView):lookup_field = 'id'serializer_class = CommentsSerializerdef 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+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/f0069400-e4e4-41a4-8503-6662a7f624c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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/CANR2ZjuXJmdUw6aRWAExUnLKXBk8i%3Dsg_5BJcb7Sy1VWHvu5Kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment