vvangelovski / django-audit-log

Audit log for your Django models
Other
232 stars 93 forks source link

Fix for audit_log ForeignKey on custom AUTH_USER_MODEL. #16

Closed tysonclugg closed 9 years ago

tysonclugg commented 9 years ago

We were getting an error when using "audit_log = AuditLog()" on a custom user model (inheriting from django.contrib.auth.mdoels.AbstractBaseUser):

$ manage.py validate
CommandError: System check identified some issues:

ERRORS:
karaage.PersonAuditLogEntry.action_user: (fields.E300) Field defines a relation with model 'karaage.Person', which is either not installed, or is abstract.

System check identified 1 issue (2 silenced).

The quick and dirty fix was to compare the kwargs['related_name'] with the relation target (to) and use "self" instead. We're open to alternate fixes...

vvangelovski commented 9 years ago

I understand the problem. This is definitely something I haven't thought of or tried to do in practice before. But, I don't think I like the solution on first sight. Maybe there is a cleaner way to do this easily. I will give it a better thought in the next few days.

Thanks

vvangelovski commented 9 years ago

This LastUserField is not used only to track log entries it can be used standalone. And in a case where it's used standalone, with this fix it will still cause a problem. Also I don't particularly like the approach of doing string comparisons to check for the case. I'm cooking something up that should fix the problem.

vvangelovski commented 9 years ago

Actually, when using the LastUserField on a custom auth user it won't be a problem because you can set the 'to' argument manually like on a ForeignKey . I fixed this issue with my last commit. I will do a release on pypi tonight. However, I'm not completely satisfied even with the solution that I came up with cause it's comparing strings again. But it is what it is. It's hard to do it otherwise and I think the solution I came up with is not very prone to breakage because of a change in another place (say the naming convention in the audit log).

Thanks for reporting the problem and your solution

brianmay commented 9 years ago

This request I believe was closed by 529327db618d63dccbce6f682cb27ec99c6997af.