42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
from __future__ import unicode_literals
|
||
|
from django.db import models
|
||
|
from django.utils import timezone
|
||
|
from ih import images
|
||
|
import os
|
||
|
|
||
|
class Post(models.Model):
|
||
|
name = models.CharField(max_length=30, blank=True)
|
||
|
file = models.FileField(upload_to='images')
|
||
|
# thumb = models.CharField(max_length=32, null=True, blank=True)
|
||
|
|
||
|
def publish(self):
|
||
|
self.published_date = timezone.now()
|
||
|
print(self.__dict__)
|
||
|
self.save()
|
||
|
|
||
|
def __unicode__(self):
|
||
|
return self.name
|
||
|
|
||
|
def thumb_name(self):
|
||
|
x = str(self.file)
|
||
|
t = x.split('/')
|
||
|
|
||
|
return '/thumb_' + t[1]
|
||
|
|
||
|
thumb_name = property(thumb_name)
|
||
|
|
||
|
def orig_name(self):
|
||
|
x = str(self.file)
|
||
|
return x.split('/')[1]
|
||
|
orig_name = property(orig_name)
|
||
|
|
||
|
'''def resize_image(self.file):
|
||
|
path, file_long = os.path.split(self.file)
|
||
|
|
||
|
im=image.open(file_long)
|
||
|
size = 128, 128
|
||
|
im.thumbnail(size)
|
||
|
im.save(thumb_name)
|
||
|
property(resize_image)'''
|