forked from yahyaaly151989/Mastering_Django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating custom template tags and filters to show a list of the lates…
…t posts and most commented posts in the sidebar
- Loading branch information
1 parent
c0dcdd1
commit ebc0bd5
Showing
15 changed files
with
361 additions
and
3 deletions.
There are no files selected for viewing
249 changes: 249 additions & 0 deletions
249
Module03/mysite/.idea/inspectionProfiles/Project_Default.xml
Large diffs are not rendered by default.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
Module03/mysite/.idea/inspectionProfiles/profiles_settings.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<ul> | ||
{% for post in latest_posts %} | ||
<li> | ||
<a href="{{ post.get_absolute_url }}">{{ post.title }}</a> | ||
</li> | ||
{% endfor %} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file added
BIN
+184 Bytes
Module03/mysite/blog/templatetags/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added
BIN
+1.96 KB
Module03/mysite/blog/templatetags/__pycache__/blog_tags.cpython-311.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django import template | ||
from ..models import Post | ||
from django.db.models import Count | ||
from django.utils.safestring import mark_safe | ||
import markdown | ||
|
||
register = template.Library() | ||
|
||
@register.simple_tag | ||
def total_posts(): | ||
return Post.objects.count() | ||
|
||
|
||
@register.inclusion_tag('blog/post/latest_posts.html') | ||
def show_latest_posts(count=5): | ||
latest_posts = Post.objects.order_by('-publish')[:count] | ||
return {'latest_posts': latest_posts} | ||
|
||
@register.simple_tag | ||
def get_most_commented_posts(count=5): | ||
return Post.objects.annotate(total_comments=Count('comments')).order_by('-total_comments')[:count] | ||
|
||
|
||
@register.filter(name='markdown') | ||
def markdown_format(text): | ||
return mark_safe(markdown.markdown(text)) |
Binary file not shown.