user12535249
user12535249

Reputation:

How i display specific page for specidfic logged in user in django

i want to display specific tasks for specific people....like if raj is logged in then tasks of raj should display not others. so please give me some solution...

views.py(home fn)

def home(request):
   username=request.session['username']
   for username in username:
      todo_items=TODO.objects.all().order_by("-created_date")
      return render(request,'main/index.html', 
                                   {'todo_items':todo_items,'username':username})

models.py

from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class TODO(models.Model):
    user=models.ForeignKey(User,on_delete=models.SET_NULL, null=True)
    created_date=models.DateTimeField()
    text=models.CharField(max_length=200)

Upvotes: 0

Views: 32

Answers (1)

bmons
bmons

Reputation: 3392

you can do it this way with request.user

def home(request):
    todo_items=TODO.objects.filter(user=request.user).order_by("-created_date")
    return render(request,'main/index.html', 
                                   {'todo_items':todo_items,})

and username in any template is available by request.user.username

Upvotes: 1

Related Questions