diff --git a/reddit/admin.py b/reddit/admin.py index 1098c95..9c857b9 100644 --- a/reddit/admin.py +++ b/reddit/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from reddit.models import RedditAccount class RedditAccountAdmin(admin.ModelAdmin): - list_display = ('username', 'user', 'date_created', 'link_karma', 'comment_karma') + list_display = ('username', 'user', 'date_created', 'link_karma', 'comment_karma', 'last_update') search_fields = ['username', 'user'] admin.site.register(RedditAccount, RedditAccountAdmin) diff --git a/reddit/models.py b/reddit/models.py index 358d9e5..b4f7435 100644 --- a/reddit/models.py +++ b/reddit/models.py @@ -19,6 +19,8 @@ class RedditAccount(models.Model): link_karma = models.IntegerField("Link Karma", blank=True, null=True) comment_karma = models.IntegerField("Comment Karma", blank=True, null=True) + last_update = models.DateTimeField("Last Update from API", blank=False) + def save(self): try: jsondoc = json.load(urllib.urlopen("http://reddit.com/user/%s/about.json" % self.username)) @@ -31,6 +33,8 @@ class RedditAccount(models.Model): self.comment_karma = data['comment_karma'] self.reddit_id = data['id'] self.date_created = datetime.fromtimestamp(data['created_utc']) + + self.last_update = datetime.now() return models.Model.save(self)