next post function
This commit is contained in:
@@ -15,6 +15,10 @@ class PostManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset()
|
||||
class NewsPostManager(models.Manager):
|
||||
"""
|
||||
Provide a query set only for "News"
|
||||
regular meetings should not be contained in the news stream
|
||||
"""
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(~Q(is_fetsitzung=True))
|
||||
|
||||
|
||||
@@ -8,10 +8,23 @@ from rest_framework import viewsets
|
||||
from rest_framework import permissions
|
||||
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from django.core.cache import cache
|
||||
|
||||
def get_next_dict():
|
||||
posts=Post.news_objects.order_by('-public_date').values('slug')
|
||||
print(posts)
|
||||
d={}
|
||||
print(d)
|
||||
for k,v in enumerate(posts):
|
||||
if k ==len(posts)-1:
|
||||
break
|
||||
d[v['slug']]=posts[k+1]['slug']
|
||||
print(d)
|
||||
return d
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
posts=deque(Post.objects.all())
|
||||
posts=deque(Post.objects.order_by('-public_date').all())
|
||||
f=lambda p: p.tags
|
||||
t=map(f, posts)
|
||||
|
||||
@@ -22,13 +35,11 @@ def tags(request,tag=""):
|
||||
return render(request, 'posts/index.html', {"posts": posts, "tags_list":None })
|
||||
|
||||
def show(request,id=None):
|
||||
print("id: %s" % id)
|
||||
print("is_digit:%s" % id.isdigit())
|
||||
if id.isdigit() or id is int:
|
||||
p=Post.objects.get(id=int(id))
|
||||
elif id != ""and not id is None:
|
||||
p=Post.objects.get(slug=(id))
|
||||
return render(request, 'posts/show.html', {"post":p})
|
||||
return render(request, 'posts/show.html', {"post":p,"next":get_next_dict().get(p.slug,None)})
|
||||
|
||||
|
||||
class PostViewSet(viewsets.ModelViewSet):
|
||||
|
||||
Reference in New Issue
Block a user