Skip to content

Commit 72bd958

Browse files
committed
fix: change errors and create users api endpoints
1 parent 79101ea commit 72bd958

File tree

25 files changed

+152
-39
lines changed

25 files changed

+152
-39
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ GitHub.sublime-settings
140140
# private_key.pem
141141
# public_key.pem
142142

143-
db.sqlite3
143+
db.sqlite3
144+
poetry.lock
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from rest_framework import routers
2+
3+
4+
router = routers.DefaultRouter()

apps/blog/sitemaps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PostSitemap(Sitemap):
77
priority = 0.9
88

99
def items(self):
10-
return Post.published.all()
10+
return Post.published.filter(is_active=True)
1111

1212
def lastmod(self, obj):
1313
return obj.updated_at
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from rest_framework import routers
2+
3+
from .users import UserViewSet, UserProfileViewSet
4+
5+
6+
router = routers.DefaultRouter()
7+
router.register("user", UserViewSet)
8+
router.register("user_profile", UserProfileViewSet)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .views import * # noqa
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from apps.users.models import User, UserProfile
2+
3+
from rest_framework import serializers
4+
5+
6+
class MiniUserProfileSerializer(serializers.ModelSerializer):
7+
class Meta:
8+
model = UserProfile
9+
fields = [
10+
"id",
11+
"avatar",
12+
"bio",
13+
]
14+
15+
16+
class UserSerializer(serializers.ModelSerializer):
17+
profiles = MiniUserProfileSerializer(read_only=True)
18+
19+
class Meta:
20+
model = User
21+
fields = [
22+
"id",
23+
"first_name",
24+
"last_name",
25+
"username",
26+
"email",
27+
"is_active",
28+
"is_superuser",
29+
"is_staff",
30+
"post_count",
31+
"profiles",
32+
]

apps/users/api_endpoints/users/User/tests.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from apps.users.models import User
2+
from .serializers import UserSerializer
3+
4+
from rest_framework import viewsets
5+
6+
7+
class UserViewSet(viewsets.ModelViewSet):
8+
queryset = User.objects.all()
9+
serializer_class = UserSerializer
10+
11+
__all__ = ("UserViewSet", )
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .views import * # noqa
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from rest_framework import serializers
2+
3+
from apps.users.models import UserProfile
4+
5+
6+
class UserProfileSerializer(serializers.ModelSerializer):
7+
class Meta:
8+
model = UserProfile
9+
fields = ["id", "avatar", "bio", "user"]

0 commit comments

Comments
 (0)