N
N
Nikolino2018-05-02 00:50:45
Django
Nikolino, 2018-05-02 00:50:45

How to display the posts of the user (author)?

models.py

class Post(models.Model):
    author = models.ForeignKey('auth.User', on_delete=models.CASCADE)

views.py
def beats_by_user(request, author):
    beats = Post.objects.get(author=author)
    return render(request, 'blog/beat_list.html', {'beats': beats})

urls.py
url(r'^profile_view/(?P<author>\w+)/$', views.beats_by_user, name='beats')

What am I doing wrong?
Post.objects.filter(author='keal')
Outputs Invalid literal for int()
Although author_id outputs

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
planc, 2018-05-02
@Nikolino

Post.objects.filter(author__username='keal')
https://docs.djangoproject.com/en/dev/topics/db/qu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question