Skip to content

Commit 9bcb47b

Browse files
Fix: Ensure UserAccount always has a Profile
Addresses RelatedObjectDoesNotExist: UserAccount has no profile errors. - Configured account/apps.py to load signals, ensuring Profile creation on UserAccount creation. - Updated account/views.py to use get_or_create for Profile access, preventing errors for users without an existing profile.
1 parent 8bf0920 commit 9bcb47b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

account/apps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
class AccountConfig(AppConfig):
55
default_auto_field = 'django.db.models.BigAutoField'
66
name = 'account'
7+
8+
def ready(self):
9+
import account.signals # noqa

account/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def me(self, request, *args, **kwargs):
7171
"""
7272
try:
7373
# Get the user's profile for serialization
74-
profile = request.user.profile
74+
profile, created = Profile.objects.get_or_create(user=request.user)
7575

7676
if request.method == "GET":
7777
serializer = UserProfileSerializer(profile, context={'request': request})

0 commit comments

Comments
 (0)