[Answered ]-Django โ€“ list of logged in user's posts

2๐Ÿ‘

โœ…

You have to store user which posted it in your post model and then you can easily filter out those.

I would update model like:

class Post(models.Model):
    owner = models.ForeignKey('User')
    # your other fields

And admin view :

@login_required(login_url='/panel/')
def adminView(request):
    draft_list = Post.objects.filter(owner=request.user).filter(isdraft=True).order_by("-posted")
    #------------------------------^^^^ filter based on owner
    p_draft = Paginator(draft_list,15)

    publish_list = Post.objects.filter(owner=request.user).filter(isdraft=False).order_by("-posted")
    p_publish = Paginator(publish_list,15)
    #your other view code
    ...

Also, you will have to update the view which adds a post to put owner as well.

๐Ÿ‘คRohan

Leave a comment