diff --git a/apps/blog/views.py b/apps/blog/views.py
--- a/apps/blog/views.py
+++ b/apps/blog/views.py
@@ -26,6 +26,8 @@
from tagging.views import tagged_object_list
from render import render
+from django.db.models import Q
+
def _get_reply_to(request):
try:
return int(request.GET.get('reply_to', None))
@@ -35,7 +37,15 @@
def post_list(request, *args, **kwargs):
"""Post listing. Only shows posts that are older than now()"""
- kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
+
+ if request.user.id:
+ # the OR clause includes logged-in user's drafts as well
+ q_lookup = (Q(is_draft=False) | Q(author=request.user))
+ # exclude future posts on the premise that drafts are always current
+ kwargs['queryset'] = Post.whole_objects.filter(q_lookup).exclude(date__gt=dt.now())
+ else:
+ kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
+
return object_list(request, *args, **kwargs)
This can be rewritten as:
if request.user.id:
qs = ...
else:
qs = Post.objects
kwargs['queryset'] = qs.exclude(date...)
This will keep us DRY. ;-)
--
Alexander
diff --git a/apps/blog/views.py b/apps/blog/views.py
--- a/apps/blog/views.py
+++ b/apps/blog/views.py
@@ -26,6 +26,8 @@
from tagging.views import tagged_object_list
from render import render
+from django.db.models import Q
+
def _get_reply_to(request):
try:
return int(request.GET.get('reply_to', None))
@@ -35,7 +37,18 @@
def post_list(request, *args, **kwargs):
"""Post listing. Only shows posts that are older than now()"""
- kwargs['queryset'] = Post.objects.exclude(date__gt=dt.now())
+
+
+ if request.user.id:
+ # the OR clause includes logged-in user's drafts as well
+ q_lookup = (Q(is_draft=False) | Q(author=request.user))
+ qs = Post.whole_objects.filter(q_lookup)
+ else:
+ qs = Post.objects
+
+ # hide all posts that are not yet published
+ kwargs['queryset'] = qs.exclude(date__gt=dt.now())
I'm not a huge fan of assigning the manager instance as if it was
the query set, but I submitted a patch like that.
Thanks!
--
mjt
--
Best regards, Yuri V. Baburov, ICQ# 99934676, Skype: yuri.baburov,
MSN: bu...@live.com
Maybe.
I'll cook up a patch like that if requested, but I'm kinda busy with
other stuff now.
Still I think the last one is good enough :)
--
mjt