Basic support for entries of 'photo' kind

This commit is contained in:
Danielle McLean 2017-10-27 16:04:05 +11:00
parent 1912251801
commit aec22e813d
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
4 changed files with 34 additions and 2 deletions

View file

@ -37,7 +37,12 @@ Article = Entry(
fields=('slug', 'name'), fields=('slug', 'name'),
) )
Photo = Entry(
id='photo',
icon='fa fa-camera',
plural='photos',
)
all = (Note, Article) all = (Note, Article, Photo)
from_id = {k.id: k for k in all} from_id = {k.id: k for k in all}
from_plural = {k.plural: k for k in all} from_plural = {k.plural: k for k in all}

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-27 04:57
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('entries', '0004_auto_20171027_0846'),
]
operations = [
migrations.AddField(
model_name='entry',
name='photo',
field=models.ImageField(blank=True, upload_to=''),
),
migrations.AlterField(
model_name='entry',
name='kind',
field=models.CharField(choices=[('note', 'note'), ('article', 'article'), ('photo', 'photo')], db_index=True, default='note', max_length=30),
),
]

View file

@ -26,6 +26,7 @@ class Entry(ModelMeta, models.Model):
) )
name = models.CharField(max_length=100, blank=True) name = models.CharField(max_length=100, blank=True)
photo = models.ImageField(blank=True)
content = models.TextField() content = models.TextField()
author = models.ForeignKey( author = models.ForeignKey(
@ -54,7 +55,7 @@ class Entry(ModelMeta, models.Model):
@property @property
def image_url(self): def image_url(self):
return self.author.avatar_url return self.photo.url if self.photo else self.author.avatar_url
def __str__(self): def __str__(self):
return '{kind} {id}: {content}'.format( return '{kind} {id}: {content}'.format(

View file

@ -1,4 +1,5 @@
{% load humanize markdown %}<article class="card h-entry"> {% load humanize markdown %}<article class="card h-entry">
{% if entry.photo %}<img class="card-img-top u-photo" src="{{ entry.photo.url }}" />{% endif %}
<div class="card-body"> <div class="card-body">
{% if entry.name %}<h4 class="card-title p-name">{{ entry.name }}</h4>{% endif %} {% if entry.name %}<h4 class="card-title p-name">{{ entry.name }}</h4>{% endif %}
<div class="e-content{% if not entry.name %} p-name{% endif %}">{{ entry.content | markdown }}</div> <div class="e-content{% if not entry.name %} p-name{% endif %}">{{ entry.content | markdown }}</div>