jazzband / django-auditlog

A Django app that keeps a log of changes made to an object.
MIT License
1.15k stars 413 forks source link

Add AbstractLogEntry class to allow extension without creating additional table #580

Open fugimuse opened 1 year ago

fugimuse commented 1 year ago

I would like to be able to extend LogEntry with custom fields without introducing an additional table. I think this can be be accomplished by introducing a new class AbstractBaseLogEntry, containing all of the code from LogEntry and adding:

class AbstractBaseLogEntry
    class Meta:
        abstract = True

    # Existing code from LogEntry

class LogEntry(AbstractBaseLogEntry):
    pass

New fields could then be accommodated in the log as follows:

# In myapp.models

from auditlog.models import AbstractBaseLogEntry

class CustomLogEntry(AbstractBaseLogEntry):
    new_field1 = models.CharField(max_length=255, blank=True, null=True)
fugimuse commented 1 year ago

If this seems like a good idea, I would be interested in taking it on and submitting a pull request.

hramezani commented 1 year ago

Thanks @fugimuse for bringing this. Yeah, seems a good idea.

CleitonDeLima commented 1 month ago

@fugimuse Is this in progress? I can make the change if no one has started yet.

hramezani commented 1 month ago

@CleitonDeLima feel free to work on this

CleitonDeLima commented 1 month ago

A slightly off-topic question: @hramezani how should I configure my environment correctly for this project? I configured venv, pip install -e . and pip install django, run the tests with runtests.py/tox. Is there anything else I need to configure? Sometimes I miss not having a manage.py to create migrations, por example.

hramezani commented 1 month ago

A slightly off-topic question: @hramezani how should I configure my environment correctly for this project? I configured venv, pip install -e . and pip install django, run the tests with runtests.py/tox. Is there anything else I need to configure? Sometimes I miss not having a manage.py to create migrations, por example.

I also use the same setup. not sure what the problem is.

CleitonDeLima commented 1 month ago

I also use the same setup. not sure what the problem is.

I created this draft, but I can't run the tests with a new CustomLogEntryModel.

Maybe I configured the tests incorrectly.

hramezani commented 1 month ago

I also use the same setup. not sure what the problem is.

I created this draft, but I can't run the tests with a new CustomLogEntryModel.

Maybe I configured the tests incorrectly.

Thanks @CleitonDeLima for the PR and sorry for late reply! Unfortunatelly I am busy these days and can't help you a a lot to fix the problem.

Have you checked the CI error django.db.utils.ProgrammingError: relation "django_content_type" does not exist?

you probably should be able to run the test easily by tox e.g. tox -e py310-django50