Open
Description
Describe the bug
Sidenote: thank you so much for the m2m field tracking! Stopped me migrating a large project to django-pghistory.
Unfortunately it doesn't work correctly in the admin integration. When I view a historic item, it will always show the current selection on an m2m field instead of the selection at the specific time.
The same is happening when using as_of()
and I suspect the issues are related.
To Reproduce
Steps to reproduce the behavior:
- Create a model with an m2m field
- In the admin, create an object and select one item on the m2m field and save.
- Then edit again and unselect that item and select another one and save.
- When going into the history, it will always show the latest selection even for older version.
Code to reproduce:
# models.py
from django.db import models
from simple_history.models import HistoricalRecords
class Tag(models.Model):
name = models.TextField()
def __str__(self):
return self.name
class Testing(models.Model):
tags = models.ManyToManyField(Tag)
history = HistoricalRecords(m2m_fields=[tags])
# admin.py
from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import Tag, Testing
@admin.register(Testing)
class TestingAdmin(SimpleHistoryAdmin):
pass
@admin.register(Tag)
class TestingTagAdmin(SimpleHistoryAdmin):
pass
Expected behavior
It should show the selection as it was at the time.
Environment
- Django Simple History Version: 3.2.0 and latest commit 6d09c3e
- Django Version: 4.1.3