summaryrefslogtreecommitdiff
path: root/app/normalize/models.py
blob: b99ae1e3209db0d08833681fff7995b588d95eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.db import models
from django.apps import apps
from django.contrib.contenttypes.models import ContentType


class RelatedPost(models.Model):
    model_name = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL)
    entry_id = models.IntegerField()
    title = models.CharField(max_length=200)
    slug = models.CharField(max_length=50)
    post_type = models.CharField(null=True, blank=True, max_length=50)
    pub_date = models.DateTimeField('Date published')

    class Meta:
        ordering = ('-model_name', '-pub_date',)
        get_latest_by = 'pub_date'

    def __str__(self):
        if self.model_name.name == 'post':
            print(self.entry_id)
            try:
                p = apps.get_model("posts", "Post").objects.get(id=self.entry_id)
            except:
                print(self.title)
            return "%s - %s" % (p.get_post_type_display(), self.title)
        else:
            return "%s - %s" % (self.model_name, self.title)