拍爱

models.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # -*- coding: utf-8 -*-
  2. from django.conf import settings
  3. from django.db import models
  4. from django.utils.translation import ugettext_lazy as _
  5. from pai2.basemodels import CreateUpdateMixin
  6. import datetime
  7. import os
  8. import time
  9. def upload_path(instance, old_filename):
  10. extension = os.path.splitext(old_filename)[1].lower()
  11. today = datetime.datetime.today()
  12. return 'file/{year}{month}/{timestamp}{extension}'.format(
  13. year=today.year,
  14. month=today.month,
  15. timestamp=time.time(),
  16. extension=extension
  17. )
  18. class LatestAppInfo(CreateUpdateMixin):
  19. latest_version = models.CharField(_(u'latest_version'), max_length=255, help_text=u'最新版本')
  20. latest_app = models.FileField(_(u'latest_app'), upload_to=upload_path, blank=True, null=True, help_text=u'最新版 APP')
  21. latest_url = models.URLField(_(u'latest_url'), max_length=255, blank=True, null=True, help_text=u'最新版 APP 链接')
  22. class Meta:
  23. verbose_name = _('latestappinfo')
  24. verbose_name_plural = _('latestappinfo')
  25. def __unicode__(self):
  26. return u'{0.pk}'.format(self)
  27. @property
  28. def final_latest_url(self):
  29. return self.latest_url or u'{0}{1}'.format(settings.DOMAIN, self.latest_app and self.latest_app.url)
  30. def _data(self):
  31. return {
  32. 'latest_version': self.latest_version,
  33. 'latest_url': self.final_latest_url,
  34. }
  35. data = property(_data)
  36. class SplashInfo(CreateUpdateMixin):
  37. splash_image = models.ImageField(_(u'splash_image'), upload_to=upload_path, blank=True, null=True, help_text=u'启动页面图片')
  38. spalash_image_airtime = models.DateTimeField(_(u'spalash_image_airtime'), blank=True, null=True, help_text=u'启动页面图片开始日期')
  39. spalash_image_deadline = models.DateTimeField(_(u'spalash_image_deadline'), blank=True, null=True, help_text=u'启动页面图片截止日期')
  40. class Meta:
  41. verbose_name = _('splashinfo')
  42. verbose_name_plural = _('splashinfo')
  43. def __unicode__(self):
  44. return u'{0.pk}'.format(self)
  45. @property
  46. def splash_image_url(self):
  47. return self.splash_image and (settings.DOMAIN + self.splash_image.url)
  48. def _data(self):
  49. return {
  50. 'splash_image_url': self.splash_image_url,
  51. 'spalash_image_airtime': self.spalash_image_airtime,
  52. 'spalash_image_deadline': self.spalash_image_deadline,
  53. }
  54. data = property(_data)
  55. class FeedbackInfo(CreateUpdateMixin):
  56. user_id = models.CharField(_(u'user_id'), max_length=255, blank=True, null=True, help_text=u'用户唯一标识')
  57. feedback = models.TextField(_(u'feedback'), blank=True, null=True, help_text=u'用户反馈')
  58. class Meta:
  59. verbose_name = _('feedbackinfo')
  60. verbose_name_plural = _('feedbackinfo')
  61. def __unicode__(self):
  62. return u'{0.pk}'.format(self)