Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleHistoryAdmin.history_view always use AUTH_USER_MODEL for generating the URL under "Changed By" #1302

Open
epou opened this issue Jan 25, 2024 · 0 comments

Comments

@epou
Copy link

epou commented Jan 25, 2024

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)
  1. Instantiate a new Poll object while specifying the user responsible for the modification.
  2. Navigate to http://<HOSTNAME>/admin/<APP>/poll/<PK>/history/ (retrieve from reverse(f"admin:{obj._meta.app_label}_{obj._meta.model_name}_history", args=[quote(obj.pk)])).
  3. Select the link under the "Changed By" column.
  4. 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).

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

No branches or pull requests

1 participant