Commit 1bab4749 authored by Leila's avatar Leila
Browse files

create button tag

parent f6e53c1f
Pipeline #456 skipped
from django.db import models
from django.utils.translation import ugettext_lazy as _
from taggit.managers import TaggableManager
import random
import string
......@@ -43,6 +44,8 @@ class Post(models.Model):
intro_pic = models.ImageField(blank=True, null=True)
author = models.ForeignKey('Author')
tags = TaggableManager()
class Meta:
ordering = ['-publish_on']
......
......@@ -16,6 +16,9 @@
<div class="intro-pic">
<img src="{{object.intro_pic.url}}">
</div>
{% for tag in object.tags.all %}
<a href="{% url 'tagged_entries' tag.slug %}" class="tag btn btn-default btn-sm">{{ tag }}</a>
{% endfor %}
<button class="readmore btn btn-sm" type="submit">
<a href="{% url 'post_details' object.pk %}">Read more</a>
</button>
......
......@@ -3,6 +3,8 @@ from django.views.generic.edit import FormView
from django.core.urlresolvers import reverse_lazy
from taggit.models import Tag
from .models import Contact, Post
from .forms import ContactForm
......@@ -31,3 +33,19 @@ class PostDetailsView(DetailView):
model = Post
template_name = 'cuisine_entre_amis/post_details.html'
class PostTaggedView(PostView):
def get_queryset(self):
slug = self.kwargs.get('slug', '')
queryset = super(PostTaggedView, self).get_queryset()
return queryset.filter(tags__slug__iexact=slug)
def get_contect_data(self, **kwargs):
context = super(PostTaggedView, self).get_contect_data(**kwargs)
slug = self.kwargs.get('slug', '')
tag = Tag.object.filter(slug__iexact=slug)
if len(tag):
context['cur_tag']=tag[0]
return context
......@@ -31,6 +31,7 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'taggit',
'crispy_forms',
'cookielaw',
......
......@@ -4,7 +4,7 @@ from django.conf.urls.static import static
from django.contrib import admin
from cuisine_entre_amis.views import ContactView, PostView, PostDetailsView
from cuisine_entre_amis.views import ContactView, PostView, PostDetailsView, PostTaggedView
# from cuisine_entre_amis.views import HomeView
......@@ -15,6 +15,7 @@ urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^contact/$', ContactView.as_view(template_name='cuisine_entre_amis/contact.html'), name='contact'),
url(r'^tagged/(?P<slug>[\w-]+)\.html$', PostTaggedView.as_view(), name='tagged_entries'),
url(r'^$', PostView.as_view(template_name='cuisine_entre_amis/post.html'), name='post'),
url(r'^Detail/(?P<pk>[0-9]+)/$', PostDetailsView.as_view(template_name='cuisine_entre_amis/post_details.html'), name='post_details'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment