Basic support for entries of 'photo' kind
This commit is contained in:
parent
1912251801
commit
aec22e813d
4 changed files with 34 additions and 2 deletions
|
@ -37,7 +37,12 @@ Article = Entry(
|
|||
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_plural = {k.plural: k for k in all}
|
||||
|
|
25
entries/migrations/0005_auto_20171027_1557.py
Normal file
25
entries/migrations/0005_auto_20171027_1557.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -26,6 +26,7 @@ class Entry(ModelMeta, models.Model):
|
|||
)
|
||||
|
||||
name = models.CharField(max_length=100, blank=True)
|
||||
photo = models.ImageField(blank=True)
|
||||
content = models.TextField()
|
||||
|
||||
author = models.ForeignKey(
|
||||
|
@ -54,7 +55,7 @@ class Entry(ModelMeta, models.Model):
|
|||
|
||||
@property
|
||||
def image_url(self):
|
||||
return self.author.avatar_url
|
||||
return self.photo.url if self.photo else self.author.avatar_url
|
||||
|
||||
def __str__(self):
|
||||
return '{kind} {id}: {content}'.format(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% 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">
|
||||
{% 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>
|
||||
|
|
Loading…
Reference in a new issue