question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom return classes does not display objects in logentry table

See original GitHub issue

I am having a problem with the audit log for classes that have a customised return. For example I have this code:

          class Adress(models.Model):
            type_id= models.ForeignKey(AddressType)
            street = models.CharField(max_length=256, null=True)
            number = models.CharField(max_length=16, null=True)
            zip_code= models.CharField(max_length=16, null=True)
            city = models.CharField(max_length=64, null=True)
            country = models.CharField(max_length=64, null=True)

          def __str__(self):
             return self.city

          auditlog.register(Adress)

My database records everything nicely, however, the object that changed is not logged because I have a custom return.

See printscreen example subnets and networks:

screen shot 2017-09-11 at 11 36 30

If I remove the returns I get the object notation properly. But I have a lot of forms where the foreign key needs to be displayed the return I give it, for example “city” for class address. But if I change something with that class, it only returns the city in the table where I would like to see “Address Object”.

Hope you can help me out!

Best, Dylienne

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DylienneKTVcommented, Sep 12, 2017

Hello Audiolion,

I understand, thank you.

However, the returns are very much alike as all are ipv4 addresses. I would like to make a distinction between subnets, networks, ip’s, pub.ip’s etc. In the logentry column, they all return ipv4 notations where it then is not to be distinguished at what object the object_repr belongs to.

Your solution is okay for this project. Thank you.

Best,

0reactions
audiolioncommented, Sep 12, 2017

You can write your own get_additional_data method to return additional information about the object in a json format that will be tracked by auditlog

https://github.com/jjkester/django-auditlog/blob/v0.4.3/src/auditlog_tests/models.py#L87

then you can access it on the log_entry object through the additional_data property

https://github.com/jjkester/django-auditlog/blob/v0.4.3/src/auditlog_tests/tests.py#L219

The code that runs it is https://github.com/jjkester/django-auditlog/blob/master/src/auditlog/models.py#L44

basically check if the model being saved has a callable get_addtional_data and if so add the result to an additional_data property on the log entry

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django - Custom Admin Actions Logging - Stack Overflow
Show activity on this post. All changes you do in Django Admin is logged in the table django_admin_table and you can also see...
Read more >
The Django admin site
Do you need a ModelAdmin object at all? In the preceding example, the ModelAdmin class doesn't define any custom values (yet). As a...
Read more >
Error Processing | Using ObjectScript | InterSystems IRIS Data ...
Describes the three types of InterSystems ObjectScript error handling: TRY and CATCH blocks, the %Status return code, and $ZTRAP error trapping.
Read more >
Console log formatting - .NET - Microsoft Learn
Learn how to use available console log formatting, or implement custom log formatting for your .NET applications.
Read more >
Adding Logging in Angular Applications - CODE Magazine
The date/time is not that important when just logging to the console ... The LogEntry class, shown in Listing 4, has properties for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found