Answer the question
In order to leave comments, you need to log in
List of posts by a specific user?
How can I make an authorized user see in his profile a list of articles that he published on the site? Each article has the name of the author.
#models
class Post(models.Model):
title = models.CharField(max_length=100)
text = models.TextField()
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
date = models.DateTimeField(default=timezone.now)
#views
def post_list(request):
posts = Post.objects.all()
return render(request, 'home/post_list.html', {'posts':posts})
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render(request, 'home/post_detail.html', {'post':post})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question