Skip to content

Commit

Permalink
Create Clipping page, model, view and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Jun 23, 2024
1 parent b29b034 commit 48e3be9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/blog/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from blog.models import Category, Post, PostImage
from blog.models import Category, Clipping, Post, PostImage
from django.contrib import admin

admin.site.register(Category)
admin.site.register(PostImage)
admin.site.register(Clipping)


@admin.register(Post)
Expand Down
26 changes: 26 additions & 0 deletions src/blog/jinja2/blog/clipping.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends '/core/home.jinja2' %}

{% block extra_css %}
<link rel="stylesheet" href="{{ static('css/blog.css') }}">
{% endblock %}

{% block content %}
<div id="blog-area">
{% block button %}
{% endblock %}
{% block page_title %}
<h2>{{ _("Clippings") }}</h2>
{% endblock page_title %}
{% for clipping in clippings %}
<div class="post">
<h3>{{ clipping.title }}</h3>
<p>{{ clipping.created.date() }} </p>
<p>{{ clipping.description }}</p>
<a href="{{ clipping.link }}">{{ clipping.link }}</a>
<br />
<br />
<a href="{{ clipping.file.url }}">{{ _("Download File")}}</a>
</div>
{% endfor %}
</div>
{% endblock %}
1 change: 0 additions & 1 deletion src/blog/jinja2/blog/post_preview.jinja2
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% set count = 1 %}
{% for post in posts %}
<div class="post">
<h3><a href="{{ url('blog_detail', args=[post.pk])}}">{{ post.title }}</a></h3>
Expand Down
13 changes: 13 additions & 0 deletions src/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ def __str__(self):
return self.file.name.lstrip(IMAGE_BASE_PATH)


class Clipping(models.Model):
id = models.BigAutoField(primary_key=True)
title = models.CharField(max_length=200)
description = models.CharField(max_length=500)
link = models.URLField()
file = models.FileField(upload_to="clipping_files/")
created = models.DateTimeField(auto_now_add=True, editable=True)
updated = models.DateTimeField(auto_now=True, editable=True)

def __str__(self):
return self.title


class Post(models.Model):
id = models.BigAutoField(primary_key=True)
title = models.CharField(max_length=200)
Expand Down
1 change: 1 addition & 0 deletions src/blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
urlpatterns = [
path("", views.blog_index, name="blog_index"),
path("post/<int:pk>/", views.blog_detail, name="blog_detail"),
path("clippings/", views.clipping, name="clippings"),
path("category/<category>/", views.blog_category, name="blog_category"),
]
8 changes: 7 additions & 1 deletion src/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from blog.models import Category, Post, PostStatus
from blog.models import Category, Clipping, Post, PostStatus
from django.shortcuts import render

PREVIEW_SIZE = 300
Expand Down Expand Up @@ -62,3 +62,9 @@ def blog_detail(request, pk):
context = {"post": post, "images": post.images.all()}

return render(request, "blog/detail.jinja2", context)


def clipping(request):
clippings = Clipping.objects.all().order_by("-created")
context = {"clippings": clippings}
return render(request, "blog/clipping.jinja2", context)
3 changes: 3 additions & 0 deletions src/core/jinja2/core/useful_links.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<div class="">
<a href="{{ url('blog_index') }}">{{ _('Blog') }}</a>
</div>
<div class="">
<a href="{{ url('clippings') }}">{{ _('Clippings') }}</a>
</div>
<div class="">
<a href="{{ url('profile') }}">{{ _('My Stuff') }}</a>
</div>
Expand Down

0 comments on commit 48e3be9

Please sign in to comment.