Skip to content

Allow having multiple user_model/remove user_model from HistoricalRecords #1518

@mariusty

Description

@mariusty

When a project contains multiple user models that can edit the same model, it’s not possible to add history.

The issue arises because HistoricalRecords enforces a single user_model, which doesn’t work when different types of users can modify the same object.

Example:

class BusinessOwnerUser(models.Model):
        name = models.CharField(max_length=150, null=True, blank=True)

class CustomerUser(models.Model):
        name = models.CharField(max_length=150, null=True, blank=True)

class Invoice(models.Model):
        title = models.CharField(max_length=150, null=True, blank=True)
        history = HistoricalRecords()

if a customer user changes the Invoice there is an error
"Cannot assign \"<CustomerUser: 7 7>\": \"HistoricalInvoice.history_user\" must be a \"BusinessOwnerUser\" instance.

I've tried:

  • leave the user_model parameter for HistoricalRecords empty
  • use BusinessOwnerUser as user_model parameter
  • use a list of user_model parameter for HistoricalRecords
  • write a custom history_user_setter:
def set_historical_user_none(historical_instance):
    historical_instance.history_user_id = None

I think it would be nice to have an option to disable user_model if needed OR to allow multiple user models to be linked to the historical model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions