Skip to content

m2m: Admin doesn't show m2m of historic object #1063

Open
@duebbert

Description

@duebbert

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:

  1. Create a model with an m2m field
  2. In the admin, create an object and select one item on the m2m field and save.
  3. Then edit again and unselect that item and select another one and save.
  4. 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

Metadata

Metadata

Assignees

Labels

bugIssues related to confirmed bugs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions