djongo
djongo copied to clipboard
int() argument must be a string, a bytes-like object or a number, not 'ObjectId'
id is not autogenerated in mongodb when given id in serializer it throws this error
Python script
<copy and paste code here>
class Order(models.Model):
owner = models.ForeignKey(to= User, on_delete= models.CASCADE)
fromlocation = models.CharField(max_length=256)
tolocation = models.CharField(max_length=256)
vehicletype = models.CharField(max_length=256)
vehicleroof = models.CharField(max_length=16)
partialweight = models.IntegerField()
loadtype = models.CharField(max_length=16)
date = models.DateField()
time = models.TimeField()
status = models.CharField(max_length= 16)
Traceback
i've had the same issue, current workaround i've found is to:
- install uuid
- add this field to the model
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
uuid is builtin - no need to insall anything
@pokorny-martin that's a dirty workaround (creates id
field in Mongo next to already existing _id
one) but I can confirm it works.
However this bug needs a proper solution.