class Post(models.Model): PUBLISH_CHOICES = ((1, _('Draft')), (2, _('Published'))) slug = models.SlugField(max_length=256) title_en = models.CharField(max_length=1024, blank=True) title_fr = models.CharField(max_length=1024, blank=True) title = i18n_field('title') content_en = models.TextField(blank=True) content_fr = models.TextField(blank=True) content = i18n_field('content') created = models.DateField(auto_now_add=True) publish = models.DateField(blank=True, null=True) status = models.IntegerField(choices=PUBLISH_CHOICES, default=2) logo = models.ImageField(upload_to='post', null=True, blank=True) author = models.ForeignKey(User, on_delete=models.CASCADE) category = models.ForeignKey('Category', related_name='posts', on_delete=models.CASCADE) objects = models.Manager() published_objects = PublishedManager() class Meta: db_table = 'blog_post' ordering = ('-publish', ) get_latest_by = 'publish' def __str__(self): return self.slug def get_absolute_url(self): return reverse_lazy('blog_detail', kwargs={ 'year': self.publish.year, 'month': self.publish.strftime('%m').lower(), 'slug': self.slug }) def html_content(self): try: return self._html_content except AttributeError: md = Markdown(extensions=['meta']) self._html_content = md.convert(self.content) return self._html_content def striped_content(self): return strip_tags(self.html_content()) def clean(self): if self.status == 2 and self.publish is None: raise ValidationError( _("Need a valid publish date before publishing"))
class Sponsor(models.Model): name = models.CharField(max_length=32) slug = models.SlugField(max_length=256) url = models.URLField( blank=True, null=True, ) logo = models.ImageField(upload_to='sponsors') ordering = models.IntegerField(default=0) frontpage = models.BooleanField( default=False, help_text='Display on frontpage', ) partner = models.BooleanField( default=False, help_text='Display as a partner', ) description_en = models.TextField(blank=True) description_fr = models.TextField(blank=True) description = i18n_field('description') @property def description_html(self): md = Markdown(extensions=['meta']) return md.convert(self.description) def __str__(self): return self.name @property def has_description(self): return self.description_en and self.description_fr
class Category(models.Model): slug = models.SlugField(max_length=64) title_en = models.CharField(max_length=64) title_fr = models.CharField(max_length=64) title = i18n_field('title') logo = ImageField(upload_to='category', default='category/default.jpg') class Meta: db_table = 'blog_categories' ordering = ('slug', ) verbose_name_plural = _('Categories') def __unicode__(self): return u"{0}".format(self.slug) def get_absolute_url(self): return reverse_lazy('blog_category', kwargs={'slug': self.slug})
class Video(models.Model): slug = models.SlugField(max_length=256) code = models.CharField(max_length=15) post = models.ForeignKey(Post, related_name="videos") title_en = models.CharField(max_length=64) title_fr = models.CharField(max_length=64) title = i18n_field('title') class Meta: db_table = 'blog_video' ordering = ('post', ) verbose_name_plural = _('Videos') def __unicode__(self): return u"{0}".format(self.title) def get_absolute_url(self): return reverse_lazy('video', kwargs={"slug": self.slug})