Skip to content

Commit f633fb0

Browse files
50 - Published and Draft Posts
1 parent 31ff0d6 commit f633fb0

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/blog/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class BlogPostForm(forms.Form):
1212
class BlogPostModelForm(forms.ModelForm):
1313
class Meta:
1414
model = BlogPost
15-
fields = ['title', 'slug', 'content']
15+
fields = ['title', 'slug', 'content', 'publish_date']
1616

1717
def clean_title(self, *args, **kwargs):
1818
instance = self.instance

src/blog/templates/blog/list-inline.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class='col-12 col-md-10 mb-3 mx-auto'>
2-
<div class='card'>
2+
<div class='card {% if not blog_post.publish_date %} border border-warning text-dark {% endif %}'>
33
<div class='card-body'>
44
<h5 class='card-title'>{{ blog_post.title }}</h5>
55
<p class='card-text'>
6-
6+
<small class='text-muted'>{{ blog_post.publish_date }}</small>
77
{% if truncate %}
88
{{ blog_post.content|linebreaks|truncatewords:30 }}
99
{% else %}
@@ -12,7 +12,9 @@ <h5 class='card-title'>{{ blog_post.title }}</h5>
1212
</p>
1313

1414
{% if not detail %}
15+
{% if not blog_post.publish_date %} Draft {% endif %}
1516
<a href="{{ blog_post.get_absolute_url }}">View</a>
17+
1618
{% endif %}
1719
</div>
1820

src/blog/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def blog_post_list_view(request):
2121
# list out objects
2222
# could be search
2323
qs = BlogPost.objects.all().published() # queryset -> list of python object
24+
if request.user.is_authenticated:
25+
my_qs = BlogPost.objects.filter(user=request.user)
26+
qs = (qs | my_qs).distinct()
2427
template_name = 'blog/list.html'
2528
context = {'object_list': qs}
2629
return render(request, template_name, context)

0 commit comments

Comments
 (0)