aboutsummaryrefslogtreecommitdiffstats
path: root/piccast/feeds/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'piccast/feeds/models.py')
-rw-r--r--piccast/feeds/models.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/piccast/feeds/models.py b/piccast/feeds/models.py
index 925bc87..ea7a34a 100644
--- a/piccast/feeds/models.py
+++ b/piccast/feeds/models.py
@@ -6,6 +6,10 @@ class Category(models.Model):
def __unicode__(self):
return self.name
+
+ def serializable(self):
+ return {'id': self.id,
+ 'name': self.name }
class PicFeed(models.Model):
#id
@@ -16,9 +20,25 @@ class PicFeed(models.Model):
title = models.CharField(max_length=80, blank=True)
description = models.TextField(blank=True)
image = models.ForeignKey('feeds.Pic', blank=True, null=True)
+ category = models.ForeignKey('feeds.Category', null=True,blank=True)
def __unicode__(self):
return self.shortname
+
+ def serializable(self):
+ return {'id': self.id,
+ 'created_unixtime':
+ (int(self.created.strftime("%s")) if self.created else None),
+ 'shortname': self.shortname,
+ 'source_url': self.source_url,
+ 'rssfeed_url': self.rssfeed_url,
+ 'title': self.title,
+ 'description': self.description,
+ 'image':
+ (self.image.serializable_short() if self.image else None),
+ 'category':
+ (self.category.name if self.category else None),
+ }
class PicSet(models.Model):
#id
@@ -34,6 +54,20 @@ class PicSet(models.Model):
def __unicode__(self):
return self.title
+
+ def serializable(self):
+ return {'id': self.id,
+ 'created_unixtime':
+ (int(self.created.strftime("%s")) if self.created else None),
+ 'source_url': self.source_url,
+ 'title': self.title,
+ 'description': self.description,
+ 'keywords': self.keywords,
+ 'image':
+ (self.image.serializable_short() if self.image else None),
+ 'category':
+ (self.category.name if self.category else None),
+ }
class Pic(models.Model):
#id
@@ -51,4 +85,26 @@ class Pic(models.Model):
def __unicode__(self):
return self.title
+
+ def serializable(self):
+ return {'id': self.id,
+ 'set': {'id': self.set.id, 'title': self.set.title },
+ 'thumbnail_url': self.thumbnail_url,
+ 'thumbnail_height': self.thumbnail_height,
+ 'thumbnail_width': self.thumbnail_width,
+ 'original_url': self.original_url,
+ 'original_height': self.original_height,
+ 'original_width': self.original_width,
+ 'source_url': self.source_url,
+ 'caption': self.caption,
+ 'is_nsfw': self.is_nsfw,
+ }
+
+ def serializable_short(self):
+ # TODO: more here?
+ return {'id': self.id,
+ 'original_url': self.original_url,
+ 'original_height': self.original_height,
+ 'original_width': self.original_width,
+ }