aboutsummaryrefslogtreecommitdiff
path: root/middleware/userprofilemiddleware.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-12-16 18:38:05 +0000
committerBobby <[email protected]>2024-12-16 18:38:05 +0000
commitea8f5e8517161c1bd52f61198138dfd2fc72f8e2 (patch)
tree19dd955137c8c6bb9c1143bbced320737cd93b09 /middleware/userprofilemiddleware.py
parent04788ddd83c5e80a09a468d07427f0e365db71d7 (diff)
downloadthatcomputerscientist-ea8f5e8517161c1bd52f61198138dfd2fc72f8e2.tar.xz
thatcomputerscientist-ea8f5e8517161c1bd52f61198138dfd2fc72f8e2.zip
its all in a state of chaos, but it shall be working soon
Diffstat (limited to 'middleware/userprofilemiddleware.py')
-rw-r--r--middleware/userprofilemiddleware.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/middleware/userprofilemiddleware.py b/middleware/userprofilemiddleware.py
index 96a7997e..a7d2a281 100644
--- a/middleware/userprofilemiddleware.py
+++ b/middleware/userprofilemiddleware.py
@@ -6,7 +6,11 @@ from apps.blog.models import Post
class UserProfileMiddleware(MiddlewareMixin):
def process_request(self, request):
if request.user.is_authenticated:
- user_profile = UserProfile.objects.get(user=request.user)
+ try:
+ user_profile = UserProfile.objects.get(user=request.user)
+ except UserProfile.DoesNotExist:
+ user_profile = UserProfile(user=request.user)
+ user_profile.save()
request.user.profile = user_profile
request.user.profile.weblogs_created = Post.objects.filter(
author=request.user