diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/normalize/migrations/0004_relatedpost_post_type.py | 18 | ||||
-rw-r--r-- | app/normalize/models.py | 8 | ||||
-rw-r--r-- | app/posts/models.py | 2 |
3 files changed, 26 insertions, 2 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) diff --git a/app/posts/models.py b/app/posts/models.py index 302d278..857b619 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -245,7 +245,7 @@ def cache_gravatar(sender, comment, **kwargs): @receiver(post_save, sender=Post) def post_save_events(sender, update_fields, created, instance, **kwargs): - related, created = RelatedPost.objects.get_or_create(model_name=instance.get_content_type(), entry_id = instance.id, pub_date=instance.pub_date, title=instance.title, slug=instance.slug) + related, created = RelatedPost.objects.get_or_create(model_name=instance.get_content_type(), entry_id = instance.id, pub_date=instance.pub_date, title=instance.title, slug=instance.slug, post_type=instance.get_post_type_display()) post_save.disconnect(post_save_events, sender=Post) instance.save() post_save.connect(post_save_events, sender=Post) |