diff options
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | piccast/feeds/models.py | 79 |
2 files changed, 46 insertions, 38 deletions
@@ -39,3 +39,8 @@ Feed Scrape Command Run "./manage.py scrape_feeds acidcow" to fetch the RSS feed for acid cow and scape all the (new) picture sets. +TODO +---- +- scrape description text from acidcow +- refactor sets to include pic_count column (generated when scraping, updating) + diff --git a/piccast/feeds/models.py b/piccast/feeds/models.py index ea7a34a..cf8fc77 100644 --- a/piccast/feeds/models.py +++ b/piccast/feeds/models.py @@ -11,6 +11,45 @@ class Category(models.Model): return {'id': self.id, 'name': self.name } +class Pic(models.Model): + #id + set = models.ForeignKey('feeds.PicSet', null=True,blank=True) + title = models.CharField(max_length=128, blank=False) + thumbnail_url = models.URLField(blank=True) + thumbnail_height = models.PositiveIntegerField(null=True,blank=True) + thumbnail_width = models.PositiveIntegerField(null=True,blank=True) + original_url = models.URLField(blank=False) + original_height = models.PositiveIntegerField(null=True,blank=True) + original_width = models.PositiveIntegerField(null=True,blank=True) + source_url = models.URLField(blank=True) + caption = models.TextField(blank=True) + is_nsfw = models.NullBooleanField(null=True, blank=True) + + 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, + } + class PicFeed(models.Model): #id created = models.DateTimeField() @@ -65,46 +104,10 @@ class PicSet(models.Model): 'keywords': self.keywords, 'image': (self.image.serializable_short() if self.image else None), + 'pic_count': + Pic.objects.filter(set=self.id).count(), 'category': (self.category.name if self.category else None), } -class Pic(models.Model): - #id - set = models.ForeignKey('feeds.PicSet', null=True,blank=True) - title = models.CharField(max_length=128, blank=False) - thumbnail_url = models.URLField(blank=True) - thumbnail_height = models.PositiveIntegerField(null=True,blank=True) - thumbnail_width = models.PositiveIntegerField(null=True,blank=True) - original_url = models.URLField(blank=False) - original_height = models.PositiveIntegerField(null=True,blank=True) - original_width = models.PositiveIntegerField(null=True,blank=True) - source_url = models.URLField(blank=True) - caption = models.TextField(blank=True) - is_nsfw = models.NullBooleanField(null=True, blank=True) - - 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, - } |