Add basic django-meta support to entries too
This commit is contained in:
parent
eaf84459ff
commit
0d520c0fd8
3 changed files with 38 additions and 3 deletions
19
entries/migrations/0003_remove_entry_summary.py
Normal file
19
entries/migrations/0003_remove_entry_summary.py
Normal file
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,12 +3,14 @@ from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
|
||||||
|
from meta.models import ModelMeta
|
||||||
from users.models import Profile
|
from users.models import Profile
|
||||||
|
|
||||||
from . import kinds
|
from . import kinds
|
||||||
ENTRY_KINDS = [(k.id, k.__name__) for k in kinds.all]
|
ENTRY_KINDS = [(k.id, k.__name__) for k in kinds.all]
|
||||||
|
|
||||||
|
|
||||||
class Entry(models.Model):
|
class Entry(ModelMeta, models.Model):
|
||||||
kind = models.CharField(
|
kind = models.CharField(
|
||||||
max_length=30,
|
max_length=30,
|
||||||
choices=ENTRY_KINDS,
|
choices=ENTRY_KINDS,
|
||||||
|
@ -16,7 +18,6 @@ class Entry(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
name = models.CharField(max_length=100, blank=True)
|
name = models.CharField(max_length=100, blank=True)
|
||||||
summary = models.TextField(blank=True)
|
|
||||||
content = models.TextField()
|
content = models.TextField()
|
||||||
|
|
||||||
author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
||||||
|
@ -24,6 +25,20 @@ class Entry(models.Model):
|
||||||
published = models.DateTimeField()
|
published = models.DateTimeField()
|
||||||
updated = 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):
|
def __str__(self):
|
||||||
return '{kind} {id}: {content}'.format(
|
return '{kind} {id}: {content}'.format(
|
||||||
kind=self.kind,
|
kind=self.kind,
|
||||||
|
|
|
@ -14,5 +14,6 @@ def entry(request, id, slug=None):
|
||||||
entry = Entry.objects.get(pk=id)
|
entry = Entry.objects.get(pk=id)
|
||||||
return render(request, 'entries/entry.html', {
|
return render(request, 'entries/entry.html', {
|
||||||
'entry': entry,
|
'entry': entry,
|
||||||
'title': entry.name or entry.content
|
'title': entry.name or entry.content,
|
||||||
|
'meta': entry.as_meta(request)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue