Django Simple History: Don't want to track User

442 Views Asked by At

I'm working on a Django project, and I'd like to use Django Simple History to track changes to records. However, I'm facing an issue: I don't want to track the user who made the change (I'm not using Django's auth app).

When I try to perform the migrations, I receive this error message:

SystemCheckError: System check identified some issues:

ERRORS:
my_app.HistoricalModel.history_user: (fields.E300) Field defines a relation with model
 'auth.User', which is either not installed, or is abstract.
data_lake.HistoricalInstance.history_user: (fields.E307) 
The field my_app.HistoricalInstance.history_user was declared with a lazy reference to 
'auth.user', but app 'auth' isn't installed.

Is there a way to use the HistoricalRecords model disabling references to user model?

1

There are 1 best solutions below

3
DanielM On

There are mentioning it in the documentation here

There are three parameters to HistoricalRecords or register that facilitate the ability to track a history_user manually: history_user_id_field, history_user_getter, history_user_setter.

In your case, you might want to change the model of the user, you can do it when defining HistoricalRecords as well:

def set_historical_user_none(historical_instance, user):
    historical_instance.history_user_id = None

class MyModal(models.Model):
   history = HistoricalRecords(
                 user_model={django_model}, 
                 history_user_setter=set_historical_user_none)