python - Displaying specific posts using django -


i have post application in django different staff members can create post. want able display each posters post when log in , not include others post.

model

class post(models.model):     """docstring post."""     user = models.foreignkey(settings.auth_user_model, default=1) #blank=true, null=true)#default=1     title = models.charfield(max_length = 120)     slug = models.slugfield(unique= true)     draft = models.booleanfield(default = false)     publish = models.datefield(auto_now=false, auto_now_add=false)     content = models.textfield()     updated = models.datetimefield(auto_now=true, auto_now_add=false)     timestamp = models.datetimefield(auto_now=false, auto_now_add=true)      #objects = postmanager()      def __str__(self):         return self.title 

view

def index(request):     results = post.objects.all().filter(draft=false)#.filter(publish__lte=timezone.now())     que = request.get.get("q")     if que:         results =results.filter(             q(title__icontains=que)|             q(content__icontains=que)).distinct()     paginator = paginator(results, 8) # show 25 contacts per page     pages ="page"     page = request.get.get('page')     try:         query = paginator.page(page)     except pagenotaninteger:         # if page not integer, deliver first page.         query = paginator.page(1)     except emptypage:         # if page out of range (e.g. 9999), deliver last page of results.         query = paginator.page(paginator.num_pages)     context = {         "objects": query,         "pages": pages     }     template = 'index.html'     return render(request,template,context) 

and additional code uploaded on request. thanks

user see own posts

results = post.objects.all().filter(draft=false).filter(publish__lte=timezone.now()) results = results.filter(user=request.user) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -