diff --git a/accounts/views.py b/accounts/views.py index c16fb34..2c36d76 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -8,6 +8,8 @@ from django.views.generic import ListView, DetailView, CreateView, UpdateView from django.contrib.auth import login, authenticate from django.shortcuts import render, redirect +from django.shortcuts import render, get_object_or_404 +from .models import CustomUser, Follow, Post class UserViewSet(viewsets.ModelViewSet): queryset = CustomUser.objects.all() @@ -44,6 +46,22 @@ class UserUpdateView(UpdateView): fields = ['username', 'email', 'bio', 'profile_picture'] success_url = '/' + + +def user_profile(request, user_id): + user = get_object_or_404(CustomUser, id=user_id) + posts = Post.objects.filter(user=user) + followers = Follow.objects.filter(following=user) + following = Follow.objects.filter(follower=user) + context = { + 'user': user, + 'posts': posts, + 'followers': followers, + 'following': following, + } + return render(request, 'accounts/profile.html', context) + + @api_view(['POST']) @permission_classes([IsAuthenticated]) def follow_user(request, user_id): diff --git a/templates/accounts/profile.html b/templates/accounts/profile.html new file mode 100644 index 0000000..c890063 --- /dev/null +++ b/templates/accounts/profile.html @@ -0,0 +1,32 @@ +{% extends 'base.html' %} + +{% block content %} +
{{ user.bio }}
+ +{{ post.content }}
+ +