From 54806ef2b80af51c682553f4ef53f021c8f82160 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 31 Jan 2019 08:42:56 -0600 Subject: added pitch tracking system and taxonomy system across models --- app/publications/models.py | 107 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 app/publications/models.py (limited to 'app/publications/models.py') diff --git a/app/publications/models.py b/app/publications/models.py new file mode 100644 index 0000000..9163602 --- /dev/null +++ b/app/publications/models.py @@ -0,0 +1,107 @@ +from django.contrib.gis.db import models +from django.utils import timezone +from django.utils.text import slugify +from django.urls import reverse + +from taggit.managers import TaggableManager + +from taxonomy.models import TaggedItems + + +class Publication(models.Model): + name = models.CharField(max_length=250) + slug = models.SlugField(unique_for_date='pub_date', blank=True) + notes = models.TextField(blank=True) + tags = TaggableManager(through=TaggedItems, blank=True, help_text='Topics Covered') + PUB_STATUS = ( + (0, 'Not Published'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) + date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + + class Meta: + ordering = ('-name', '-date_created') + + def __str__(self): + return self.name + + def get_absolute_url(self): + return reverse("publications:pub-detail", kwargs={"slug": self.slug}) + + def save(self, *args, **kwargs): + if not self.id: + self.date_created = timezone.now() + self.date_updated = timezone.now() + super(Publication, self).save() + + +class Section(models.Model): + """ Generic model for Categories """ + name = models.CharField(max_length=250) + slug = models.SlugField(blank=True) + date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) + date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + + def __str__(self): + return self.name + + def save(self, *args, **kwargs): + if self._state.adding: + self.slug = slugify(self.name)[:50] + super(Section, self).save() + + +class Editor(models.Model): + first_name = models.CharField(max_length=250) + last_name = models.CharField(max_length=250) + email = models.CharField(max_length=250, blank=True) + phone = models.CharField(max_length=250, blank=True) + twitter = models.CharField(max_length=250, blank=True) + slug = models.SlugField(blank=True) + notes = models.TextField(blank=True) + publication = models.ForeignKey(Publication, on_delete=models.SET_NULL, blank=True, null=True) + section = models.ManyToManyField(Section, blank=True) + date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) + date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + + class Meta: + ordering = ('-last_name', '-date_created') + + def __str__(self): + return "{0} {1}".format(self.first_name, self.last_name) + + def get_absolute_url(self): + return reverse("publications:pub-detail", kwargs={"slug": self.slug}) + + def save(self, *args, **kwargs): + if self._state.adding: + self.slug = slugify('%s %s' % (self.first_name, self.last_name))[:50] + self.date_created = timezone.now() + self.date_updated = timezone.now() + super(Editor, self).save() + + +class Pitch(models.Model): + title = models.CharField(max_length=250) + pitch = models.TextField() + slug = models.SlugField(blank=True) + editor = models.ForeignKey(Editor, on_delete=models.SET_NULL, blank=True, null=True) + accepted = models.BooleanField(null=True, blank=True) + date_sent = models.DateTimeField(blank=True, null=True) + date_created = models.DateTimeField(blank=True, auto_now_add=True, editable=False) + date_updated = models.DateTimeField(blank=True, auto_now=True, editable=False) + + class Meta: + ordering = ('-title', '-date_sent') + + def __str__(self): + return self.title + + def save(self, *args, **kwargs): + if self._state.adding: + self.slug = slugify(self.title)[:50] + self.date_created = timezone.now() + self.date_updated = timezone.now() + super(Pitch, self).save() -- cgit v1.2.3-70-g09d2