Skip to content

Commit

Permalink
posts: Add field for image caption
Browse files Browse the repository at this point in the history
  • Loading branch information
Andraz Vrhovec committed Dec 29, 2020
1 parent e8cd286 commit d24321a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
9 changes: 6 additions & 3 deletions sledilnik/posts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class PostResource(ModelResource):
class Meta:
resource_name = "posts"
queryset = Post.objects.all()
fields = ["id", "created", "updated", "author", "title", "image", "blurb", "link_to", "body"]
fields = ["id", "created", "updated", "author", "title",
"image", "image_caption", "blurb", "link_to", "body"]
cache = SimpleCache(timeout=60, public=True)

def get_object_list(self, request):
Expand All @@ -34,7 +35,9 @@ def dehydrate(self, bundle):
translation.activate(lang)

if bundle.obj.image:
bundle.data["image"] = bundle.request.build_absolute_uri(get_thumbnail(bundle.obj.image, "800x810").url)
bundle.data["image_thumb"] = bundle.request.build_absolute_uri(get_thumbnail(bundle.obj.image, "400x405").url)
bundle.data["image"] = bundle.request.build_absolute_uri(
get_thumbnail(bundle.obj.image, "800x810").url)
bundle.data["image_thumb"] = bundle.request.build_absolute_uri(
get_thumbnail(bundle.obj.image, "400x405").url)

return bundle
18 changes: 18 additions & 0 deletions sledilnik/posts/migrations/0008_post_image_caption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.4 on 2020-12-29 14:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('posts', '0007_auto_20201215_1557'),
]

operations = [
migrations.AddField(
model_name='post',
name='image_caption',
field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Image caption'),
),
]
11 changes: 8 additions & 3 deletions sledilnik/posts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ class Post(models.Model):
created = models.DateTimeField(_("Created"), db_index=True)
updated = models.DateTimeField(_("Updated"), auto_now=True)

published = models.BooleanField(_("Published"), default=False, db_index=True)
published = models.BooleanField(
_("Published"), default=False, db_index=True)
pinned = models.BooleanField(_("Pinned"), default=False, db_index=True)

title = models.CharField(_("Title"), max_length=200)
link_to = models.URLField(_("Link to"), null=True, blank=True)
image = models.ImageField(_("Image"), upload_to="posts/%Y/%m/%d/%H/%M/%S", null=True, blank=True)
author = models.CharField(_("Author"), max_length=100, null=True, blank=True)
image = models.ImageField(
_("Image"), upload_to="posts/%Y/%m/%d/%H/%M/%S", null=True, blank=True)
image_caption = models.CharField(
_("Image caption"), max_length=200, null=True, blank=True)
author = models.CharField(
_("Author"), max_length=100, null=True, blank=True)
blurb = MarkdownField(_("Blurb"))
body = MarkdownField(_("Body"), null=True, blank=True)

Expand Down

0 comments on commit d24321a

Please sign in to comment.