Open
Description
Describe the bug
The SimpleHistoryAdmin.history_view
assumes that the user model associated with the history_user
is the one specified in AUTH_USER_MODEL, disregarding any class provided in the HistoricalRecords.user_model
argument.
To Reproduce
[Taking the example from the docs: https://django-simple-history.readthedocs.io/en/latest/user_tracking.html#change-user-model]
models.py
from django.db import models
from simple_history.models import HistoricalRecords
class PollUser(models.Model):
user_id = models.ForeignKey('auth.User')
# Only PollUsers should be modifying a Poll
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
changed_by = models.ForeignKey(PollUser)
history = HistoricalRecords(user_model=PollUser)
@property
def _history_user(self):
return self.changed_by
@_history_user.setter
def _history_user(self, value):
self.changed_by = value
admin.py
from simple_history.admin import SimpleHistoryAdmin
from .models import Poll
admin.site.register(Poll, SimpleHistoryAdmin)
- Instantiate a new Poll object while specifying the user responsible for the modification.
- Navigate to
http://<HOSTNAME>/admin/<APP>/poll/<PK>/history/
(retrieve fromreverse(f"admin:{obj._meta.app_label}_{obj._meta.model_name}_history", args=[quote(obj.pk)])
). - Select the link under the "Changed By" column.
- ISSUE: Redirects to the auth.user change URL instead of the appropriate admin URL for the PollUser
Expected behavior
Using the PollUser admin change URL (using the class provided in the HistoricalRecords.user_model
args).
Metadata
Metadata
Assignees
Labels
No labels