Django + MongoDB + Djongo: can’t json serialize ObjectId

Solution for Django + MongoDB + Djongo: can’t json serialize ObjectId
is Given Below:

I’m creating a Django APP with MongoDB using Djongo.

When I try json.dumps(my_queryset, cls=DjangoJSONEncoder) I get the following error.

Object of type ObjectId is not JSON serializable

The model

class Productos(models.Model):
    _id = models.ObjectIdField()
    id_anwen = models.IntegerField(help_text="Pedido Mínimo", blank=True, null=True, default=1)
    codigo_kinemed = models.CharField(max_length=100, blank=True, null=True)
    codigo_barra = models.CharField(max_length=100, blank=True, null=True)
    codigo_inner = models.CharField(max_length=100, blank=True, null=True)
    codigo_master = models.CharField(max_length=100, blank=True, null=True)
    item_number = models.CharField(max_length=100, blank=True, null=True)
    objects = models.DjongoManager()

Some test

If I remove _id = models.ObjectIdField() json dumps works fine but I don’t get the object’s ID info in the JSON.

How can I serialize MongoDB’s _id field for a JSON?

Any clues welcome. Thanks in advance!

The solution in this post works fine: TypeError: ObjectId(”) is not JSON serializable

I just copy it here because teh question is more targeted and it might be easier to find.