# -*- 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 HotQueryInfo(CreateUpdateMixin): query = models.CharField(_(u'query'), max_length=255, blank=True, null=True, help_text=u'搜索关键词', unique=True) class Meta: verbose_name = _(u'热门搜索') verbose_name_plural = _(u'热门搜索') def __unicode__(self): return unicode(self.pk) @property def data(self): return { 'query': self.query, } class HotRecommendInfo(CreateUpdateMixin): title = models.CharField(_(u'title'), max_length=255, blank=True, null=True, help_text=u'热门标题', unique=True) image = models.ImageField(_(u'image'), upload_to=upload_path, 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 image_url(self): return upload_file_url(self.image) @property def data(self): return { 'title': self.title, 'image_url': self.image_url, }