Sorry about the noob questions, I'm digging through the docs... that
was perfect, thanks! The implementation I'm using now looks kinda like
this:

class ArticleAdmin(models.ModelAdmin):
    def save_model(self, request, obj, form, change):
        if obj.created_at == None:
            obj.created_at = datetime.now()
        if obj.created_by == None or len(obj.created_by) == 0:
            obj.created_by = request.user.username
        obj.updated_at = datetime.now()
        obj.updated_by = request.user.username
        obj.save()

Only issue was: I had to set the created_by and updated_by fields to
blank=True in the model to defeat the validator, even though the
semantics are that they shouldn't be blank (seems hacky, is there a
better way?).

On Jan 26, 11:50 am, Eugene Wee <[email protected]> wrote:
> Hi,
>
> On Wed, Jan 27, 2010 at 3:35 AM, Ian <[email protected]> wrote:
> > How would you populate the created_by field with the username of the
> > user logged into the admin interface? Capturing the created_at seems
> > straight forward, you can override save like this
>
> Take a look at the save_model method of a ModelAdmin derived 
> class:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-me...
>
> Regards,
> Eugene Wee

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to