next post function

This commit is contained in:
2020-05-25 19:27:42 +00:00
parent 2ade6d765b
commit 429ef7846d
2 changed files with 19 additions and 4 deletions

View File

@@ -15,6 +15,10 @@ class PostManager(models.Manager):
def get_queryset(self): def get_queryset(self):
return super().get_queryset() return super().get_queryset()
class NewsPostManager(models.Manager): 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): def get_queryset(self):
return super().get_queryset().filter(~Q(is_fetsitzung=True)) return super().get_queryset().filter(~Q(is_fetsitzung=True))

View File

@@ -8,10 +8,23 @@ from rest_framework import viewsets
from rest_framework import permissions from rest_framework import permissions
from django_filters.rest_framework import DjangoFilterBackend 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. # Create your views here.
def index(request): def index(request):
posts=deque(Post.objects.all()) posts=deque(Post.objects.order_by('-public_date').all())
f=lambda p: p.tags f=lambda p: p.tags
t=map(f, posts) t=map(f, posts)
@@ -22,13 +35,11 @@ def tags(request,tag=""):
return render(request, 'posts/index.html', {"posts": posts, "tags_list":None }) return render(request, 'posts/index.html', {"posts": posts, "tags_list":None })
def show(request,id=None): def show(request,id=None):
print("id: %s" % id)
print("is_digit:%s" % id.isdigit())
if id.isdigit() or id is int: if id.isdigit() or id is int:
p=Post.objects.get(id=int(id)) p=Post.objects.get(id=int(id))
elif id != ""and not id is None: elif id != ""and not id is None:
p=Post.objects.get(slug=(id)) 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): class PostViewSet(viewsets.ModelViewSet):