imagehost/imagehosting/models.py
2017-10-11 19:01:22 +03:00

28 lines
675 B
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils import timezone
import os
class Post(models.Model):
name = models.CharField(max_length=30, blank=True)
file = models.FileField(upload_to='images')
thumb_name = property(thumb_name)
orig_name = property(orig_name)
def publish(self):
self.published_date = timezone.now()
self.save()
def __unicode__(self):
return self.name
def thumb_name(self):
x = os.path.split(self.file.name)[-1]
return '/thumb_' + x
def orig_name(self):
x = os.path.split(self.file.name)[-1]
return x