Given a model that looks like this

class Article(models.Model):
    title = models.CharField(max_length=31)
    blurb = models.CharField(max_length=255)
    created_by = models.CharField(max_length=31)
    created_at = models.DateTimeField('Created Date')

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

    def save(self):
        if self.created_at == None:
           self.created_at = datetime.now()
      super(Article, self).save()

But I think I need access to the model object prior to it getting to
save() - the request object should have the user (right) but it's not
clear how to get to it from the extension points of the admin
interface code. You can imagine wanting to capture other implicit data
from the request context (REMOTE_ADDR, USER_AGENT, etc) but the model
isn't the place to do it. Any examples of how you'd populate the
created_by implicitly would be appreciated!


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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.

Reply via email to