django-pghistory
django-pghistory copied to clipboard
Object of type UUID is not JSON serializable
We are using uuid as primary key for user in django. When using UUID, django admin login failing due to django-pghistory.
When I used model_util's UUIDField, it failed. Thus I switched to use Django's models.UUIDField, it worked.
@xjlin0 I am using Django's models.UUIDField only.
Here is my settings with serialize=False
, hope it work
import pghistory
from django.db import models
class MyModel(models.Model):
id = models.UUIDField(default=uuid4, editable=False, primary_key=True, serialize=False)
class MyModelsHistory(pghistory.get_event_model(
MyModel,
pghistory.Snapshot('mymodel.snapshot'),
name='MyModelsHistory',
related_name='history',
)):
id = models.UUIDField(db_index=True, default=uuid4, editable=False, serialize=False)
pgh_id = models.BigAutoField(primary_key=True, serialize=False)
pgh_created_at = models.DateTimeField(auto_now_add=True)
pgh_label = models.TextField(help_text='The event label.')
pgh_obj = models.ForeignKey(db_constraint=False, on_delete=models.deletion.DO_NOTHING, related_name='history', to='myapp.mymodel')
pgh_context = models.ForeignKey(db_constraint=False, null=True, on_delete=models.deletion.DO_NOTHING, related_name='+', to='pghistory.context')
This was addressed in PR #47 and released in version 2.1.0!
The default JSON serializer is now the one provided by Django, plus you can swap in your own with settings.PGHISTORY_JSON_ENCODER
thanks to @jzmiller1 !