mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added Last API Update field
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user