80 lines
2.3 KiB
Python
Executable File
80 lines
2.3 KiB
Python
Executable File
from django.db import models
|
|
from app.models import ItfModel
|
|
|
|
class EmailerIssue(ItfModel):
|
|
title = models.CharField(max_length=512)
|
|
date = models.DateField()
|
|
issue_no = models.IntegerField()
|
|
published = models.BooleanField(default=False)
|
|
|
|
def __unicode__(self):
|
|
return self.title
|
|
|
|
class Meta:
|
|
ordering = ['-issue_no']
|
|
|
|
def info_dict(self):
|
|
return {
|
|
'issue': self,
|
|
'weblinks': Weblink.objects.filter(issue=self),
|
|
'articles': EmailerArticle.objects.filter(issue=self),
|
|
'bbitems': BulletinBoardItem.objects.filter(issue=self)
|
|
}
|
|
|
|
def list_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'title': self.title
|
|
}
|
|
|
|
def main_image(self):
|
|
for article in self.emailerarticle_set.all():
|
|
if article.main_image:
|
|
return article.main_image
|
|
return None
|
|
|
|
class EmailerArticle(models.Model):
|
|
issue = models.ForeignKey(EmailerIssue)
|
|
title = models.CharField(max_length=512)
|
|
subtitle = models.TextField(blank=True)
|
|
author = models.CharField(max_length=512, blank=True)
|
|
author_bio = models.TextField(blank=True)
|
|
main_image = models.ImageField(upload_to='upload/images/emailer/', blank=True)
|
|
text = models.TextField()
|
|
position = models.IntegerField(null=True)
|
|
|
|
def __unicode__(self):
|
|
return self.title
|
|
|
|
def get_images(self):
|
|
return self.articleimage_set.all()
|
|
|
|
class ArticleImage(models.Model):
|
|
image = models.ImageField(upload_to='upload/images/emailer/')
|
|
caption = models.CharField(max_length=512, blank=True)
|
|
article = models.ForeignKey(EmailerArticle)
|
|
short_name = models.CharField(max_length=64, blank=True, help_text='Short name to insert images into article')
|
|
|
|
def __unicode__(self):
|
|
return self.caption
|
|
|
|
|
|
class Weblink(models.Model):
|
|
url = models.URLField()
|
|
title = models.CharField(max_length=512)
|
|
text = models.TextField(blank=True)
|
|
issue = models.ForeignKey(EmailerIssue)
|
|
|
|
def __unicode__(self):
|
|
return self.url
|
|
|
|
|
|
class BulletinBoardItem(models.Model):
|
|
issue = models.ForeignKey(EmailerIssue)
|
|
title = models.CharField(max_length=512)
|
|
text = models.TextField()
|
|
position = models.IntegerField(default=1)
|
|
|
|
def __unicode__(self):
|
|
return self.title
|