oxdata/poster/models.py
2009-07-14 19:06:03 +02:00

42 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import os.path
import hashlib
from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User
from django.core.files.base import ContentFile
from oxdata.lookup.models import MovieId
class Poster(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
movie_id = models.ForeignKey(MovieId, related_name='poster')
url = models.CharField(max_length=255)
def poster_path(instance, filename):
id = instance.serviceId
return os.path.join('poster', instance.service, id[:1], id[:4], id, filename)
class PosterCache(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
movie_id = models.ForeignKey(MovieId, related_name='postercache')
url = models.CharField(max_length=1024)
service = models.CharField(max_length=255)
serviceId = models.CharField(max_length=42)
image = models.ImageField(max_length=255, upload_to=poster_path)
def download(self):
if not self.image:
import oxlib.net
name = "%s.jpg" % hashlib.sha1(self.url).hexdigest()
data = oxlib.net.getUrl(self.url)
self.image.save(name, ContentFile(data))