Hi,
i am using http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser to automatically add updated_by and created_by info,
class Entry(models.Model):
name = models.CharField('name', maxlength=100)
content = models.TextField('content')
created_by = models.ForeignKey(User, related_name='entry_owner', blank=True)
updated_by = models.ForeignKey(User, related_name='entry_last_updated', blank=True)
class Admin:
fields = ((None, {
'fields': ('name', 'content')}),)
it works when the object is created for the first time, but when i try to update the entry, it is giving a ProgrammingError because of the sql created_by_id=NULL since it is never shown in Admin fields.
presently i am using this hack to get around the error,
def save(self):
if self.id:
self.created_by = Entry.objects.get(id=
self.id).created_by
self.updated_by = threadlocals.get_current_user()
is there any other approach like disabling updating the created_by_id field once the object is created ?
cheers,
Ganesh.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---
- threadlocals, created_by and save problem Ganesh KM