Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to add dynamic fields in document. If field is not defined in schema. #263

Open
varunajmera0 opened this issue Feb 11, 2019 · 0 comments

Comments

@varunajmera0
Copy link

Error - if document._dynamic: AttributeError: 'collections.OrderedDict' object has no attribute '_dynamic'

class Conversation(DynamicDocument):
poll_name = fields.StringField(required=True)
poll_votes = fields.IntField(required=True)

class PollSerializer(serializers.DynamicDocumentSerializer):
class Meta:
model = Conversation
fields = 'all'

class PollView(APIView):
permission_classes = [permissions.AllowAny]

def get(self, request):
    serializer = PollSerializer(Conversation.objects.all(), many=True)
    response = {"polls": serializer.data}
    return Response(response, status=status.HTTP_200_OK)

def post(self, request, format=None):
    data = request.data
    tag = data.pop("varun")
    serializer = PollSerializer(data=data)
    if serializer.is_valid():
        poll = Conversation(**data)
        print("varun")
        
        poll.save()
        response = serializer.data
        return Response(response, status=status.HTTP_200_OK)
    return Response(serializer.data, status=status.HTTP_200_OK)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant