mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Removed pins django app, and moved code to the core. Moved user related code out of core to the users app.
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import urllib2
|
|
from cStringIO import StringIO
|
|
|
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
|
from django.db import models
|
|
|
|
from django_images.models import Image as BaseImage
|
|
from taggit.managers import TaggableManager
|
|
|
|
from ..users.models import User
|
|
|
|
|
|
class ImageManager(models.Manager):
|
|
# FIXME: Move this into an asynchronous task
|
|
def create_for_url(self, url):
|
|
file_name = url.split("/")[-1]
|
|
buf = StringIO()
|
|
buf.write(urllib2.urlopen(url).read())
|
|
obj = InMemoryUploadedFile(buf, 'image', file_name, None, buf.tell(), None)
|
|
return Image.objects.create(image=obj)
|
|
|
|
|
|
class Image(BaseImage):
|
|
objects = ImageManager()
|
|
|
|
class Meta:
|
|
proxy = True
|
|
|
|
|
|
class Pin(models.Model):
|
|
submitter = models.ForeignKey(User)
|
|
url = models.TextField(blank=True, null=True)
|
|
description = models.TextField(blank=True, null=True)
|
|
image = models.ForeignKey(Image, related_name='pin')
|
|
published = models.DateTimeField(auto_now_add=True)
|
|
tags = TaggableManager()
|
|
|
|
def __unicode__(self):
|
|
return self.url |