2017-09-27 13:35:32 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
2017-10-10 14:19:27 +03:00
|
|
|
# from ih import images
|
2017-09-27 13:35:32 +03:00
|
|
|
import os
|
|
|
|
|
2017-10-10 14:19:27 +03:00
|
|
|
|
2017-09-27 13:35:32 +03:00
|
|
|
class Post(models.Model):
|
|
|
|
name = models.CharField(max_length=30, blank=True)
|
|
|
|
file = models.FileField(upload_to='images')
|
2017-10-10 14:19:27 +03:00
|
|
|
# thumb = models.CharField(max_length=32, null=True, blank=True)
|
2017-09-27 13:35:32 +03:00
|
|
|
|
|
|
|
def publish(self):
|
|
|
|
self.published_date = timezone.now()
|
|
|
|
print(self.__dict__)
|
|
|
|
self.save()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
2017-10-10 14:19:27 +03:00
|
|
|
def thumb_name(self):
|
|
|
|
x = os.path.split(self.file.name)[-1]
|
|
|
|
return '/thumb_' + x
|
2017-09-27 13:35:32 +03:00
|
|
|
|
|
|
|
thumb_name = property(thumb_name)
|
2017-10-10 14:19:27 +03:00
|
|
|
|
2017-09-27 13:35:32 +03:00
|
|
|
def orig_name(self):
|
2017-10-10 13:08:53 +03:00
|
|
|
|
2017-10-10 14:19:27 +03:00
|
|
|
x = os.path.split(self.file.name)[-1]
|
2017-10-10 13:08:53 +03:00
|
|
|
return x
|
|
|
|
|
2017-09-27 13:35:32 +03:00
|
|
|
orig_name = property(orig_name)
|
|
|
|
|
|
|
|
'''def resize_image(self.file):
|
|
|
|
path, file_long = os.path.split(self.file)
|
2017-10-10 14:19:27 +03:00
|
|
|
|
2017-09-27 13:35:32 +03:00
|
|
|
im=image.open(file_long)
|
|
|
|
size = 128, 128
|
|
|
|
im.thumbnail(size)
|
|
|
|
im.save(thumb_name)
|
|
|
|
property(resize_image)'''
|