Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] web/email now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Python by aaa ( 15 years ago )
class Post(models.Model):
        title = models.CharField(max_length=255)
        teaser = models.TextField(max_length=400)
 body = models.TextField()      
 user = models.ForeignKey(User)
        created = models.DateTimeField(auto_now_add=True)
 last_change = models.DateTimeField(auto_now=True)
        is_public = models.BooleanField(default = True)
        votes_positive = models.IntegerField(default=0)
        votes_negative = models.IntegerField(default=0)
        views_count = models.IntegerField(default=0)
 rating = models.IntegerField(default=0)
"""============================================================================================================="""

from django.http import Http404
from django.views.generic import list_detail
from django.shortcuts import get_object_or_404, get_list_or_404
from django.db.models import F
from blog.models import Post

def post_detail(request, post_id):
     post = get_object_or_404(Post, pk=post_id)

     # increment views counter

            Post.objects.filter(id=post_id).update(views_count=F(views_count)+1)

            
            
     # Show the detail page
     return list_detail.object_detail(
         request,
         queryset = Post.objects.all(),
         object_id = post_id,
     )

def posts_list(request):
    # Use the object_list view for the heavy lifting.
    return list_detail.object_list(
        request,
        queryset = Post.objects.all(),
    )

 

Revise this Paste

Your Name: Code Language: