I have following Djongo model:
from djongo import models
class Feedback(models.Model):
_id = models.ObjectIdField()
title = models.CharField(blank=False, max_length=100)
text = models.TextField(blank=False)
datetimestmp = models.DateTimeField(auto_now_add=True)
I have following serializer for the model above:
from rest_framework import serializers
from .models import Feedback
class FeedbackSerializer(serializers.ModelSerializer):
class Meta:
model = Feedback
fields = "__all__"
read_only_fields = ["datetimestmp", "_id"]
def create(self, validated_data):
obj = super().create(validated_data)
print(obj._id)
return obj
When I'm sending POST request to create a Feedback entry inside DB wrong id gets printed to the console:
curl -X POST -H "Conte-Type: application/json" -d '{"title": "Example Title", "text": "Example Text"}' http://127.0.0.1:8000/api/feedbacks
results in 24
being printed to the server console instead of real ObjectId from MongoDB: ObjectId("61f85ecbb0804f215c127c30")
.
Is there a way to resolve this issue? Thank you