diff options
author | luxagraf <sng@luxagraf.net> | 2019-09-18 21:14:38 -0400 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2019-09-18 21:14:38 -0400 |
commit | 5bc22c064fbc51987007d85fbc8296a998cf6e84 (patch) | |
tree | 7d961ff86c478171ffee14168e9ae3f9d09f1ca5 /app/jrnl | |
parent | 9e7aadbcf9bab0ecfcd4afc96f6a09f9fe11a197 (diff) |
added posts, consolidated essays into posts
Diffstat (limited to 'app/jrnl')
-rw-r--r-- | app/jrnl/admin.py | 8 | ||||
-rw-r--r-- | app/jrnl/migrations/0044_auto_20190917_1703.py | 18 | ||||
-rw-r--r-- | app/jrnl/models.py | 19 |
3 files changed, 39 insertions, 6 deletions
diff --git a/app/jrnl/admin.py b/app/jrnl/admin.py index d800f34..78a2630 100644 --- a/app/jrnl/admin.py +++ b/app/jrnl/admin.py @@ -4,16 +4,16 @@ from django.contrib.gis.admin import OSMGeoAdmin from django.contrib.contenttypes.admin import GenericStackedInline from utils.widgets import AdminImageWidget, LGEntryForm -from .models import Entry, HomepageCurrator, Home, RelatedPost +from .models import Entry, HomepageCurrator, Home #, RelatedPost from photos.forms import GalleryForm from photos.models import LuxImage from utils.util import get_latlon -@admin.register(RelatedPost) -class RelatedPostAdmin(admin.ModelAdmin): - pass +#@admin.register(RelatedPost) +#class RelatedPostAdmin(admin.ModelAdmin): +# pass @admin.register(Entry) diff --git a/app/jrnl/migrations/0044_auto_20190917_1703.py b/app/jrnl/migrations/0044_auto_20190917_1703.py new file mode 100644 index 0000000..c6e5d6c --- /dev/null +++ b/app/jrnl/migrations/0044_auto_20190917_1703.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-09-17 17:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('jrnl', '0043_auto_20190704_0903'), + ] + + operations = [ + migrations.RenameModel( + old_name='RelatedPost', + new_name='OldRelatedPost', + ), + ] diff --git a/app/jrnl/models.py b/app/jrnl/models.py index a88e79a..8e8e606 100644 --- a/app/jrnl/models.py +++ b/app/jrnl/models.py @@ -3,6 +3,7 @@ import os from django.dispatch import receiver from django.contrib.gis.db import models +from django.db.models.signals import post_save from django.contrib.contenttypes.fields import GenericRelation, GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.urls import reverse @@ -24,6 +25,7 @@ from photos.models import PhotoGallery, LuxImage, LuxImageSize from locations.models import Location from books.models import Book from fieldnotes.models import FieldNote +from normalize.models import RelatedPost from utils.util import render_images, parse_video, markdown_to_html @@ -37,7 +39,7 @@ def image_url_replace(s): return s -class RelatedPost(models.Model): +class OldRelatedPost(models.Model): post_model = models.ForeignKey(ContentType, null=True, on_delete=models.SET_NULL) slug = models.SlugField() @@ -77,7 +79,7 @@ class Entry(models.Model): has_video = models.BooleanField(blank=True, default=False) field_notes = models.ManyToManyField(FieldNote, blank=True) books = models.ManyToManyField(Book, blank=True) - related = models.ManyToManyField(RelatedPost, blank=True) + related = models.ManyToManyField(OldRelatedPost, blank=True) class Meta: ordering = ('-pub_date',) @@ -174,6 +176,9 @@ class Entry(models.Model): def get_image_ext(self): return self.image.url[-3:] + def get_content_type(self): + return ContentType.objects.get(app_label="jrnl", model="entry") + def save(self, *args, **kwargs): created = self.pk is None if not created: @@ -266,6 +271,16 @@ def cache_gravatar(sender, comment, **kwargs): local_grav = '%s/%s.jpg' % (grav_dir, calculate_gravatar_hash(comment.email)) urllib.request.urlretrieve(url, local_grav) + +#@receiver(post_save, sender=Entry) +#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) +# related.title = instance.title +# related.slug = instance.slug +# post_save.disconnect(post_save_events, sender=Entry) +# instance.save() +# post_save.connect(post_save_events, sender=Entry) + # from django_comments.signals import comment_will_be_posted # from django_comments import akismet |