Home:ALL Converter>Get All Changes of Any registered model of a single user django-simple-history

Get All Changes of Any registered model of a single user django-simple-history

Ask Time:2021-10-07T16:29:45         Author:Russell

Json Formatter

# settings.py

INSTALLED_APPS = [
    # ...
    'simple_history',
    # ...
]

MIDDLEWARE = [
    # ...
    'simple_history.middleware.HistoryRequestMiddleware',
    # ...
]

Models:

from django.db import models

from apps.companies.models import Company
from simple_history.models import HistoricalRecords

# Create your models here.
class User(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=20)

    history = HistoricalRecords()


class Contact(TimeStamp):
    name = models.CharField(max_length=100, verbose_name='Person Name')
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
    phone_number = models.CharField(max_length=100, verbose_name='Personal Number', null=True, blank=True)
    email = models.EmailField(null=True, blank=True, verbose_name='Personal Email')
    designation = models.CharField(max_length=100)
    history = HistoricalRecords()

    def __str__(self):
        return self.name

user = User.objects.first() is there anyway to get all changes any model by the user

Author:Russell,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69477857/get-all-changes-of-any-registered-model-of-a-single-user-django-simple-history
yy