class Photo(models.Model): ''' 照片的数据模型 ''' img_upload = models.ImageField(u'图片上传路径', upload_to='img/%Y/%m/%d', storage=ImageStorage()) img_title = models.CharField(max_length=100, unique=True, verbose_name=u'图片标题') img_context = models.TextField(max_length=100, null=True, blank=True, verbose_name=u'图片介绍') img_tags = models.ManyToManyField('Tag', blank=True) is_top = models.BooleanField(u'置顶', default=False) img_group = models.ForeignKey('PhotoGroup', blank=True) like_count = models.IntegerField(u'点赞数', default=0) display = models.BooleanField(default=True, verbose_name=u'显示') img_create_time = models.DateTimeField(u'图片发布时间', auto_now_add=True) img_update_time = models.DateTimeField(u'图片更新时间', auto_now=True) author = models.ForeignKey(User, default='admin', verbose_name=u'作者') def image_view(self): return u'<img src="%s" height="200px"/>' % (settings.MEDIA_URL + str(self.img_upload)) image_view.short_description = '图片展示' image_view.allow_tags = True class Meta: verbose_name = u'照片' verbose_name_plural = u'照片'
class YueTuanLeader(models.Model): president_img = models.ImageField(u"团长头像", upload_to='image', default=None, storage=ImageStorage()) president_type = models.CharField(u"正副级", max_length=20, default=u'团长', choices=(('0', u'团长'), ('1', u'副团长'))) president_name_cn = models.CharField(u"团长名称(中文)", max_length=20, default='') president_intro_cn = models.CharField(u"团长简介(中文)", max_length=50, default='') president_detail_cn = models.TextField(u"团长介绍详情(中文)", default='') president_name_en = models.CharField(u"团长名称(英文)", max_length=20, default='') president_intro_en = models.CharField(u"团长简介(英文)", max_length=50, default='') president_detail_en = models.TextField(u"团长介绍详情(英文)", default='') def get_abstract(self, lang, verbose): intro = { 'id': self.id, 'name_cn': self.president_name_cn, 'name_en': self.president_name_en, 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.president_img.url), 'president_type': int(self.president_type) } if lang == 'cn': intro['intro'] = self.president_intro_cn if verbose == 'detail': intro['detail'] = self.president_detail_cn else: intro['intro'] = self.president_intro_en if verbose == 'detail': intro['detail'] = self.president_detail_en return intro def __str__(self): return self.president_name_cn class Meta: verbose_name = u'乐团团长' verbose_name_plural = verbose_name
class Banner(models.Model): img = models.ImageField(u"轮播图", upload_to='image', default=None, storage=ImageStorage()) order = models.IntegerField(u"顺序", default=100) title_cn = models.CharField(u"主标题(中文)", max_length=100, default='') subtitle_cn = models.CharField(u"副标题(中文)", max_length=100, default='') title_en = models.CharField(u"主标题(英文)", max_length=100, default='') subtitle_en = models.CharField(u"副标题(英文)", max_length=100, default='') def get_abstract(self, lang): content = { 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url), 'order': self.order } if lang == 'cn': content['title'] = self.title_cn content['subtitle'] = self.subtitle_cn else: content['title'] = self.title_en content['subtitle'] = self.subtitle_en return content def show_img(self): return u'<center><img src="%s" style="height: 100px"/></center>' % self.img.url def show_title_cn(self): return u'<center><p style="line-height:100px">%s</p></center>' % self.title_cn def show_title_en(self): return u'<center><p style="line-height:100px">%s</p></center>' % self.title_en def show_order(self): return u'<center><p style="line-height:100px">%s</p></center>' % self.order show_img.allow_tags = True show_title_cn.allow_tags = True show_title_en.allow_tags = True show_order.allow_tags = True show_img.short_description = u"<center>%s</center>" % u"轮播图" show_order.short_description = u"<center>%s</center>" % u"顺序" show_title_cn.short_description = u"<center>%s</center>" % u"主标题(中文)" show_title_en.short_description = u"<center>%s</center>" % u"主标题(英文)" def __str__(self): return self.title_cn class Meta: verbose_name = u'轮播图' verbose_name_plural = verbose_name
class Project(models.Model): CATEGORY_CHOICES = (('1', u'哲学'), ('2', u'文学'), ('3', u'历史'), ('4', u'经济'), ('5', u'计算机'), ('6', u'物理'), ('0', u'其它')) name = models.CharField(u'课题名称', max_length=255) creater = models.ForeignKey(User) master = models.CharField(u'讲师', max_length=60, blank=True) m_description = models.TextField(u'讲师简介', validators=[MaxLengthValidator(500)], help_text=u"关于讲师的一些简明介绍") category = models.CharField(u'分类', max_length=30, choices=CATEGORY_CHOICES, null=True, blank=True) p_description = models.TextField(u'课程简介', validators=[MaxLengthValidator(500)]) pub_date = models.DateTimeField(editable=False) updated_date = models.DateTimeField(editable=False) total = models.IntegerField(u'总课时数') image = models.ImageField(u'图片', upload_to=determine_image_upload_path, storage=ImageStorage(), blank=True, null=True) tags = TagField(u'标签', blank=True, help_text=u"给本课程打上标签,标签间请用空间分隔") class Meta: ordering = ['-pub_date'] def __unicode__(self): return self.name @models.permalink def get_absolute_url(self): return ('pro_detail', (), {'pro_pk': self.pk}) def _get_tags(self): return Tag.objects.get_for_object(self) def _set_tags(self, tags): return Tag.objects.update_tags(self, tags) obj_tags = property(_get_tags, _set_tags) def save(self, *args, **kwargs): if not self.pk: self.pub_date = datetime.datetime.now() self.updated_date = datetime.datetime.now() super(Project, self).save(*args, **kwargs)
class Blog(models.Model): title = models.CharField(u'标题', max_length=150, db_index=True, unique=True) slug = models.SlugField(u'链接', default='', null=True, blank=True) img_upload = models.ImageField(u'封面', upload_to='cover', blank=True, storage=ImageStorage()) content = models.TextField(u'内容', ) add_time = models.DateTimeField(u'创建时间', auto_now_add=True) publish_time = models.DateTimeField(u'发布时间', null=True) update_time = models.DateTimeField(u'修改时间') published = models.BooleanField(u'发布', default=True) access_count = models.IntegerField(u'浏览量', default=1, editable=False) category = models.ForeignKey('Category', verbose_name=u'所属分类') tags = models.ManyToManyField('Tag', verbose_name=u'标签', null=True, blank=True) author = models.ForeignKey(User, verbose_name=u'作者') class Meta: verbose_name = u'文章' verbose_name_plural = u'文章' def save(self, *args, **kwargs): self.slug = slugify(self.title) modified = kwargs.pop("modified", True) if modified: self.update_time = datetime.datetime.utcnow() super(Blog, self).save(*args, **kwargs) def get_absolute_url(self): return reverse('blog:blog_detail', args=(self.id, self.slug)) def get_admin_url(self): content_type = ContentType.objects.get_for_model(self.__class__) return urlresolvers.reverse( "admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(self.id, )) def __unicode__(self): return self.title def image_view(self): return u'<img src="%s" height="200px"/>' % (settings.MEDIA_URL + str(self.img_upload)) image_view.short_description = '图片展示' image_view.allow_tags = True
class Performer(models.Model): img = models.ImageField(u"头像", upload_to='image', default=None, storage=ImageStorage()) instrument_type = models.ForeignKey(InstrumentType, verbose_name=u"演奏乐器", default=None) name_cn = models.CharField(u"名称(中文)", max_length=20, default='', unique=True) detail_cn = models.TextField(u"个人介绍(中文)", default='') name_en = models.CharField(u"名称(英文)", max_length=20, default='', unique=True) detail_en = models.TextField(u"个人介绍(英文)", default='') def get_abstract(self, lang, verbose): intro = { 'id': self.id, 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url), 'name_cn': self.name_cn, 'name_en': self.name_en } if lang == 'cn': intro['instrument_type'] = self.instrument_type.name_cn if verbose == 'detail': intro['detail'] = self.detail_cn else: intro['instrument_type'] = self.instrument_type.name_en if verbose == 'detail': intro['detail'] = self.detail_en return intro def __str__(self): return self.name_cn class Meta: verbose_name = u'乐团成员' verbose_name_plural = verbose_name
class Conductor(models.Model): img = models.ImageField(u"头像", upload_to='image', default=None, storage=ImageStorage()) name_cn = models.CharField(u"名称(中文)", max_length=20, default='', unique=True) intro_cn = models.CharField(u"简介(中文)", max_length=50, default='') detail_cn = models.TextField(u"介绍详情(中文)", default='') name_en = models.CharField(u"名称(英文)", max_length=20, default='', unique=True) intro_en = models.CharField(u"简介(英文)", max_length=50, default='') detail_en = models.TextField(u"介绍详情(英文)", default='') def get_abstract(self, lang, verbose): intro = { 'id': self.id, 'name_cn': self.name_cn, 'name_en': self.name_en, 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url), } if lang == 'cn': intro['intro'] = self.intro_cn if verbose == 'detail': intro['detail'] = self.detail_cn return intro else: intro['intro'] = self.intro_en if verbose == 'detail': intro['detail'] = self.detail_en return intro def __str__(self): return self.name_cn class Meta: verbose_name = u'驻团指挥' verbose_name_plural = verbose_name
class BusinessDynamics(models.Model): img = models.ImageField(u"缩略图", upload_to='image', default='', storage=ImageStorage()) publish_time = models.DateField(u"发布日期", default=default_time_now) title_cn = models.CharField(u"文章标题(中文)", max_length=50, default='') detail_cn = models.TextField(u"文章内容(中文)", default='') title_en = models.CharField(u"文章标题(英文)", max_length=50, default='') detail_en = models.TextField(u"文章内容(英文)", default='') def get_abstract(self, lang, verbose): content = { 'id': self.id, 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url) } if lang == 'cn': content['title'] = self.title_cn content['date'] = self.publish_time.strftime('%Y年%m月%d日') if verbose == 'abstract': content['abstract'] = utils.clip_text(self.detail_cn, keep_n=50, lang='cn') else: content['detail'] = self.detail_cn else: content['title'] = self.title_en content['date'] = self.publish_time.strftime('%Y-%m-%d') if verbose == 'abstract': content['abstract'] = utils.clip_text(self.detail_en, keep_n=100, lang='en') else: content['detail'] = self.detail_en return content def __str__(self): return self.title_cn class Meta: verbose_name = u'事业动态' verbose_name_plural = verbose_name
class account(models.Model): user = models.OneToOneField(User, unique=True) nichname = models.CharField(max_length=60, null=True, default='', blank=True) Favicon = models.ImageField(upload_to='./loginORreg/static/image/favicon/', storage=ImageStorage(), null=True, blank=True) friends = models.ManyToManyField("self", blank=True) articles = models.ManyToManyField(Article, blank=True) intristing = models.CharField(max_length=60, null=True, default='', blank=True) def __unicode__(self): return self.user.username
class Blog(models.Model): title = models.CharField(u'标题', max_length=150, db_index=True, unique=True) slug = models.SlugField(u'链接', default='', null=True, blank=True) img_upload = models.ImageField(u'封面', upload_to='cover', blank=True, storage=ImageStorage()) content = models.TextField(u'内容', ) add_time = models.DateTimeField(u'创建时间', auto_now_add=True) publish_time = models.DateTimeField(u'发布时间', null=True) update_time = models.DateTimeField(u'修改时间') published = models.BooleanField(u'发布', default=True) access_count = models.IntegerField(u'浏览量', default=1, editable=False) category = models.ForeignKey('Category', related_name='posts', on_delete=models.CASCADE, verbose_name=u'所属分类') tags = models.ManyToManyField('Tag', related_name='posts', verbose_name=u'标签', null=True, blank=True) class Meta: verbose_name = u'文章' verbose_name_plural = u'文章' ordering = ['-update_time'] def save(self, *args, **kwargs): self.slug = slugify(self.title) modified = kwargs.pop("modified", True) if modified: self.update_time = datetime.datetime.utcnow() if self.published and self.publish_time == None: self.publish_time = datetime.datetime.utcnow() super(Blog, self).save(*args, **kwargs) def __unicode__(self): return self.title
class ContactUs(models.Model): title_cn = models.CharField(u"中文标题", max_length=100, default='') content_cn = models.TextField(u"中文内容", default='') title_en = models.CharField(u"英文标题", max_length=100, default='') content_en = models.TextField(u"英文内容", default='') img = models.ImageField(u"缩略图", upload_to='image', default='', storage=ImageStorage()) def get_abstract(self, lang='cn'): info = { 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url) } if lang == 'cn': info['title'] = self.title_cn info['content'] = self.content_cn return info else: info['title'] = self.title_en info['content'] = self.content_en return info def save(self, *args, **kwargs): nb = ContactUs.objects.count() if nb == 0 or (nb == 1 and self.id): super(ContactUs, self).save(*args, **kwargs) def __str__(self): return u'联系我们' class Meta: verbose_name = u'联系我们' verbose_name_plural = verbose_name
class Article(models.Model): Title = models.CharField(max_length=256) style = models.ForeignKey(Styles, blank=True) create_time = models.DateTimeField(auto_now_add=True) update_time = models.DateTimeField(auto_now=True) filey = models.FileField(upload_to='./loginORreg/static/file/', storage=ImageStorage()) keywords1 = models.CharField(max_length=20, null=True, default='', blank=True) keywords2 = models.CharField(max_length=20, null=True, default='', blank=True) keywords3 = models.CharField(max_length=20, null=True, default='', blank=True) power = models.CharField(max_length=20, blank=True) author = models.CharField(max_length=30, null=True, default='未命名', blank=True)
class MusicFestival(models.Model): img = models.ImageField(u"图片", upload_to='image', default=None, storage=ImageStorage()) publish_time = models.DateField(u"发布日期", default=default_time_now) title_cn = models.CharField(u"中文标题", max_length=100, unique=True, default='') content_cn = models.TextField(u"中文内容", default='') title_en = models.CharField(u"英文标题", max_length=100, unique=True, default='') content_en = models.TextField(u"英文内容", default='') video = models.FileField( u"视频文件", upload_to='video', default=None, null=True, blank=True, storage=VideoStorage(), help_text=u"仅支持MP4格式视频文件,请勿上传其它格式文件!<br/>由于服务器带宽限制,视频文件可能会上传较长时间,请耐心等待." ) video_desc_cn = models.TextField(u"视频简介(中文)", default='', blank=True) video_desc_en = models.TextField(u"视频简介(英文)", default='', blank=True) def get_abstract(self, lang, verbose): intro = { 'id': self.id, 'img': "{proto}://{domain}{path}".format(proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url) } if lang == 'cn': intro['date'] = self.publish_time.strftime('%Y年%m月%d日') intro['title'] = self.title_cn if verbose == 'abstract': intro['abstract'] = utils.clip_n_rows(self.content_cn, lang='cn') else: intro['detail'] = self.content_cn try: intro['video'] = "{proto}://{domain}{path}".format( proto=config.PROTOCOL, domain=config.DOMAIN, path=self.video.url) except ValueError: intro['video'] = '' intro['video_desc'] = self.video_desc_cn else: intro['date'] = self.publish_time.strftime('%Y-%m-%d') intro['title'] = self.title_en if verbose == 'abstract': intro['abstract'] = utils.clip_n_rows(self.content_en, lang='en') else: intro['detail'] = self.content_en try: intro['video'] = "{proto}://{domain}{path}".format( proto=config.PROTOCOL, domain=config.DOMAIN, path=self.video.url) except ValueError: intro['video'] = '' intro['video_desc'] = self.video_desc_en return intro def __str__(self): return self.title_cn class Meta: verbose_name = u'乐季' verbose_name_plural = verbose_name
class Musicale(models.Model): publish_time = models.DateField(u"发布日期", default=default_time_now) title_cn = models.CharField(u"中文标题", max_length=100, unique=True, default='') content_cn = models.TextField(u"中文内容", default='') title_en = models.CharField(u"英文标题", max_length=100, unique=True, default='') content_en = models.TextField(u"英文内容", default='') img = models.ImageField(u"图片", upload_to='image', default=None, storage=ImageStorage()) def get_abstract(self, lang, verbose): if lang == 'cn': intro = { 'id': self.id, 'img': "{proto}://{domain}{path}".format( proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url, ), 'title': self.title_cn, 'date': self.publish_time.strftime('%Y年%m月%d日') } if verbose == 'detail': intro['detail'] = self.content_cn return intro else: intro = { 'id': self.id, 'img': "{proto}://{domain}{path}".format( proto=config.PROTOCOL, domain=config.DOMAIN, path=self.img.url, ), 'title': self.title_en, 'date': self.publish_time.strftime('%Y-%m-%d') } if verbose == 'detail': intro['detail'] = self.content_en return intro def __str__(self): return self.title_cn class Meta: verbose_name = u'音乐会' verbose_name_plural = verbose_name