Re: Auditing Record Changes in All Admin Tables

2011-06-01 Thread Ryan
No problem. One final piece of advice would be to move the readonly_fields out of Entity1Admin and into AuditAdmin. That way you only have to define it once and inherit from it as with all the other options rather than re-defining it for each new model. Ryan -- You received this message bec

Re: Auditing Record Changes in All Admin Tables

2011-06-01 Thread Lee
Bingo! Everything's working. Here's the complete solution for others: models.py - from django.db import models from django.contrib import admin class AuditedTable(models.Model): created = models.DateTimeField(auto_now_add=True) created_by = models.CharField(blank=True,max_length=2

Re: Auditing Record Changes in All Admin Tables

2011-06-01 Thread Ryan
That bit is the easy bit :p Just change request.user to request.user.username Ryan -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/RXpUd1BTX2E3RVVK. To po

Re: Auditing Record Changes in All Admin Tables

2011-06-01 Thread Lee
Found the solution to display the audit fields in the change list and change form -- add these lines in admin.py: class Entity1Admin(AuditAdmin): list_display = ('title','created','created_by','updated','updated_by') readonly_fields = ('created','created_by','updated','updated_by') So now I j

Re: Auditing Record Changes in All Admin Tables

2011-06-01 Thread Lee
Ryan- that helps a ton, thanks much. I don't think created_by and updated_by should be foreign keys, because a user can be deleted but all of his record adds/updates need to persist. So I replaced those two lines with: created_by = models.CharField(blank=True,max_length=20,editable=False) updated_

Re: Auditing Record Changes in All Admin Tables

2011-06-01 Thread Ryan
The model code still needs to stay in the model, it is just the save_model method had to be moved to the admin.py. I think the following is what you are looking for: models.py --- from django.db import models from django.contrib.auth.models import User class AuditedTable(models.Mod

Re: Auditing Record Changes in All Admin Tables

2011-05-31 Thread Lee
Moved it to admin.py but it ignores the auto_now parameters (leaving timestamps blank) and doesn't populate the created_by/updated_by fields either: class AuditAdmin(admin.ModelAdmin): created = models.DateTimeField(auto_now_add=True) created_by = models.CharField(blank=True,max_length=20) u

Re: Auditing Record Changes in All Admin Tables

2011-05-31 Thread Ryan
That code is supposed to go in the models admin definition like so: admin.py: -- class AuditAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): obj.user = request.user obj.save() Ryan -- You received this message bec

Re: Auditing Record Changes in All Admin Tables

2011-05-31 Thread Lee
Thanks for that tip Ryan. Here's the relevant models.py code I used to get this to _almost_ work: - class AuditedTable(models.Model): created = models.DateTimeField(auto_now_add=True) created_by = models.CharField(blank=True,max_length=20) updated = models.DateTimeField(auto_n

Re: Auditing Record Changes in All Admin Tables

2011-05-29 Thread Ryan
This will show you how to achieve this in the django admin: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Auditing Record Changes in All Admin Tables

2011-05-27 Thread Lee
All of my tables have 4 audit fields: created (timestamp) created_by (user name) updated (timestamp) updated_by (user name) I'd like to define a subclass of models.Model that sets these fields on create/update, and then make all my models of that subclass -- but all the related posts I see imply