Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

WIP: Add default many-to-many support #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

bmedx
Copy link

@bmedx bmedx commented Jan 29, 2020

Work in progress. Needs code cleanup, documentation added, and further testing (especially in the admin site) but seems to work as expected.

Adds support for Django's default many-to-many models (ones without explicit an through)

Description

Allows m2m fields to be explicitly added to the history of a model which uses HistoricalRecords. It allows access to the m2m history via a historical_{m2m_field_name} attribute.

When the parent model adds a history row, all connected m2m fields store all existing connections with a FK back to the history row. When the m2m mapping is updated (add, remove, clear) a new history row is created, firing off the same process.

Related Issue

jazzband#399
jazzband#370
jazzband#16

Motivation and Context

We need to track changes in many-to-many relationships over time.

How Has This Been Tested?

Added unit tests to cover everything I could think of.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run the make format command to format my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

simple_history/manager.py Outdated Show resolved Hide resolved
simple_history/models.py Outdated Show resolved Hide resolved
@kb3dow
Copy link

kb3dow commented Feb 18, 2020

I had a question: I am using the AdminModel, how do I see the m2m field corresponding to a historical object on the change object screen. I am using it as a non-admin user (though I have admin access too). Any historical object chosen from the admin list display screen still shows the most recent m2m values on the screen (showing details of a single object). On the list display screen I was however able to see historical m2m values by looking at the HistoricalXYZ object.

Doesn't the admin.py:history_form_view() also need a change ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants