I'm fairly new to django and programming in general, but I'll give it a shot:
Could you define a separate model for LogEntry's? If you had a separate model for the log entries, you could easily define a many-to- many field to link them. This isn't semantically beautiful, but it might work. Here's some pseudocode (you'll have to look up the actual ways to write this)... class SomeModel(models.Model): name = models.CharField(bla bla bla) #Don't let them edit log_entries in admin log_entries = models.ManyToManyField(LogEntry, editable=False) #have a field where they can edit their change. current_log_entry = models.CharField(blablabla) On Jul 11, 4:44 am, "Haestan" <haes...@hotmail.com> wrote: > > I would like to add a custom field to an existing admin model, namely > > LogEntry. The goal is to add a comment field, where custom change > > comments can be added in the admin whenever a model is saved. > > > Is it even possible to add such a field without changing the existing > > admin codebase? Or would have to define a new model and just > > override all the admin's *log* methods to save the log msgs to the > > new model? > > > Any hints how this could be done? > > Or are the any apps that do similar things, where I could take a look at? > > Actually, I found a way to do it but it's quite ugly and I guess it will be > easily broken > by any Django updates: > > <code> > from django.utils.encoding import smart_unicode > class CustomLogEntryManager(models.Manager): > def log_action(self, user_id, content_type_id, object_id, object_repr, > action_flag, change_message='', > change_comment=''): > e = self.model(None, None, user_id, content_type_id, > smart_unicode(object_id), > object_repr[:200], action_flag, change_message, change_comment) > e.save() > > from django.contrib.admin.models import LogEntry > LogEntry.add_to_class('change_comment', models.CharField(max_length=255, > blank=True)) > LogEntry.add_to_class('objects', CustomLogEntryManager()) > </code> > > Then I just override any admin methods that use LogEntry.log_action(...) to > also pass a change_comment > parameter. > > Can anyone think of a better way to do this? > Btw, I'am using 1.0.2 at the moment. Would v1.1 offer anything that would > make this more easy to implement? > > I'm grateful for any hints, design tips, etc. > > Thanks, > > tom. > > PS: sorry, that I send this mail again, I somehow managed to reply to the > wrong > message in the first place. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---