说明书

models.py 1.3KB

    # -*- coding: utf-8 -*- import os from django.db import models from django.utils.translation import ugettext_lazy as _ from TimeConvert import TimeConvert as tc from manual.basemodels import CreateUpdateMixin from utils.url_utils import upload_file_url def upload_path(instance, old_filename): return 'file/{ym}/{stamp}{ext}'.format( ym=tc.local_string(format='%Y%m'), stamp=tc.local_timestamp(ms=True), ext=os.path.splitext(old_filename)[1].lower(), ) class MessageInfo(CreateUpdateMixin): msg_image = models.ImageField(_(u'msg_image'), upload_to=upload_path, blank=True, null=True, help_text=u'消息图片') msg_image_airtime = models.DateTimeField(_(u'msg_image_airtime'), blank=True, null=True, help_text=u'消息图片开始日期') msg_image_deadline = models.DateTimeField(_(u'msg_image_deadline'), blank=True, null=True, help_text=u'消息图片截止日期') class Meta: verbose_name = _(u'图片消息') verbose_name_plural = _(u'图片消息') def __unicode__(self): return unicode(self.pk) @property def msg_image_url(self): return upload_file_url(self.msg_image) @property def data(self): return { 'msg_image_url': self.msg_image_url, }