Added Last API Update field

This commit is contained in:
2010-03-02 23:01:01 +00:00
parent e7ab428044
commit b04f943bc5
2 changed files with 5 additions and 1 deletions

View File

@@ -2,7 +2,7 @@ from django.contrib import admin
from reddit.models import RedditAccount from reddit.models import RedditAccount
class RedditAccountAdmin(admin.ModelAdmin): 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'] search_fields = ['username', 'user']
admin.site.register(RedditAccount, RedditAccountAdmin) admin.site.register(RedditAccount, RedditAccountAdmin)

View File

@@ -19,6 +19,8 @@ class RedditAccount(models.Model):
link_karma = models.IntegerField("Link Karma", blank=True, null=True) link_karma = models.IntegerField("Link Karma", blank=True, null=True)
comment_karma = models.IntegerField("Comment 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): def save(self):
try: try:
jsondoc = json.load(urllib.urlopen("http://reddit.com/user/%s/about.json" % self.username)) 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.comment_karma = data['comment_karma']
self.reddit_id = data['id'] self.reddit_id = data['id']
self.date_created = datetime.fromtimestamp(data['created_utc']) self.date_created = datetime.fromtimestamp(data['created_utc'])
self.last_update = datetime.now()
return models.Model.save(self) return models.Model.save(self)