From 0d520c0fd8743d6ca651ac21c926417a5a93a6ac Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Wed, 25 Oct 2017 14:04:22 +1100 Subject: [PATCH] Add basic django-meta support to entries too --- .../migrations/0003_remove_entry_summary.py | 19 +++++++++++++++++++ entries/models.py | 19 +++++++++++++++++-- entries/views.py | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 entries/migrations/0003_remove_entry_summary.py diff --git a/entries/migrations/0003_remove_entry_summary.py b/entries/migrations/0003_remove_entry_summary.py new file mode 100644 index 0000000..aac7f18 --- /dev/null +++ b/entries/migrations/0003_remove_entry_summary.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.6 on 2017-10-25 03:03 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('entries', '0002_syndication'), + ] + + operations = [ + migrations.RemoveField( + model_name='entry', + name='summary', + ), + ] diff --git a/entries/models.py b/entries/models.py index fb0d648..29affe3 100644 --- a/entries/models.py +++ b/entries/models.py @@ -3,12 +3,14 @@ from django.db import models from django.urls import reverse from slugify import slugify +from meta.models import ModelMeta from users.models import Profile + from . import kinds ENTRY_KINDS = [(k.id, k.__name__) for k in kinds.all] -class Entry(models.Model): +class Entry(ModelMeta, models.Model): kind = models.CharField( max_length=30, choices=ENTRY_KINDS, @@ -16,7 +18,6 @@ class Entry(models.Model): ) name = models.CharField(max_length=100, blank=True) - summary = models.TextField(blank=True) content = models.TextField() author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) @@ -24,6 +25,20 @@ class Entry(models.Model): published = models.DateTimeField() updated = models.DateTimeField() + _metadata = { + 'description': 'content', + 'twitter_creator': 'twitter_creator', + 'og_profile_id': 'og_profile_id', + } + + @property + def twitter_creator(self): + return self.author.twitter_username + + @property + def og_profile_id(self): + return self.author.facebook_id + def __str__(self): return '{kind} {id}: {content}'.format( kind=self.kind, diff --git a/entries/views.py b/entries/views.py index 1f17bb2..f8a0b19 100644 --- a/entries/views.py +++ b/entries/views.py @@ -14,5 +14,6 @@ def entry(request, id, slug=None): entry = Entry.objects.get(pk=id) return render(request, 'entries/entry.html', { 'entry': entry, - 'title': entry.name or entry.content + 'title': entry.name or entry.content, + 'meta': entry.as_meta(request) })