Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ItemBase(models.Model):
- post = models.ForeignKey(Post, related_name='%(class)s_related')
- title = models.CharField(max_length=250)
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(auto_now=True)
- class Meta:
- abstract = True
- def __str__(self):
- return self.title
- def render(self):
- return render_to_string('content/items/{}.html'.format(self._meta.model_name), {'item': self})
- class Image(ItemBase):
- image_url = models.URLField(blank=True, null=True)
- image = models.ImageField(upload_to='posts/%Y/%m/%d', blank=True, null=True)
- def get_remote_image(self):
- if self.image_url and not self.image_file:
- result = urllib.urlretrieve(self.image_url)
- self.image_file.save(
- self.title,
- File(open(result[0]))
- )
- self.save()
Advertisement
Add Comment
Please, Sign In to add comment