diff options
Diffstat (limited to 'app/normalize')
-rw-r--r-- | app/normalize/migrations/0004_relatedpost_post_type.py | 18 | ||||
-rw-r--r-- | app/normalize/models.py | 8 |
2 files changed, 25 insertions, 1 deletions
diff --git a/app/normalize/migrations/0004_relatedpost_post_type.py b/app/normalize/migrations/0004_relatedpost_post_type.py new file mode 100644 index 0000000..c95d623 --- /dev/null +++ b/app/normalize/migrations/0004_relatedpost_post_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1 on 2020-12-23 10:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('normalize', '0003_auto_20200418_0909'), + ] + + operations = [ + migrations.AddField( + model_name='relatedpost', + name='post_type', + field=models.CharField(blank=True, max_length=50, null=True), + ), + ] diff --git a/app/normalize/models.py b/app/normalize/models.py index f45f90b..8333681 100644 --- a/app/normalize/models.py +++ b/app/normalize/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.apps import apps from django.contrib.contenttypes.models import ContentType @@ -7,6 +8,7 @@ class RelatedPost(models.Model): 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: @@ -14,4 +16,8 @@ class RelatedPost(models.Model): get_latest_by = 'pub_date' def __str__(self): - return "%s - %s" % (self.model_name, self.title) + if self.model_name.name == 'post': + p = apps.get_model("posts", "Post").objects.get(id=self.entry_id) + return "%s - %s" % (p.get_post_type_display(), self.title) + else: + return "%s - %s" % (self.model_name, self.title) |