mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 07:19:36 +02:00
feat: Remove email field from user details response and enhance frontend user display
This commit is contained in:
parent
c1807826d0
commit
7d71c84fd2
8 changed files with 55 additions and 411 deletions
|
@ -3,6 +3,7 @@ import os
|
|||
from .models import Adventure, AdventureImage, ChecklistItem, Collection, Note, Transportation, Checklist, Visit, Category, Attachment
|
||||
from rest_framework import serializers
|
||||
from main.utils import CustomModelSerializer
|
||||
from users.serializers import CustomUserDetailsSerializer
|
||||
|
||||
|
||||
class AdventureImageSerializer(CustomModelSerializer):
|
||||
|
@ -80,15 +81,16 @@ class AdventureSerializer(CustomModelSerializer):
|
|||
attachments = AttachmentSerializer(many=True, read_only=True)
|
||||
category = CategorySerializer(read_only=False, required=False)
|
||||
is_visited = serializers.SerializerMethodField()
|
||||
user = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Adventure
|
||||
fields = [
|
||||
'id', 'user_id', 'name', 'description', 'rating', 'activity_types', 'location',
|
||||
'is_public', 'collection', 'created_at', 'updated_at', 'images', 'link', 'longitude',
|
||||
'latitude', 'visits', 'is_visited', 'category', 'attachments'
|
||||
'latitude', 'visits', 'is_visited', 'category', 'attachments', 'user'
|
||||
]
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id', 'is_visited']
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id', 'is_visited', 'user']
|
||||
|
||||
def validate_category(self, category_data):
|
||||
if isinstance(category_data, Category):
|
||||
|
@ -126,7 +128,11 @@ class AdventureSerializer(CustomModelSerializer):
|
|||
}
|
||||
)
|
||||
return category
|
||||
|
||||
|
||||
def get_user(self, obj):
|
||||
user = obj.user_id
|
||||
return CustomUserDetailsSerializer(user).data
|
||||
|
||||
def get_is_visited(self, obj):
|
||||
current_date = timezone.now().date()
|
||||
for visit in obj.visits.all():
|
||||
|
|
|
@ -128,7 +128,7 @@ USE_L10N = True
|
|||
USE_TZ = True
|
||||
|
||||
unParsedFrontenedUrl = getenv('FRONTEND_URL', 'http://localhost:3000')
|
||||
FRONTEND_URL = unParsedFrontenedUrl.replace("'", "").replace('"', '')
|
||||
FRONTEND_URL = unParsedFrontenedUrl.translate(str.maketrans('', '', '\'"'))
|
||||
|
||||
SESSION_COOKIE_SAMESITE = None
|
||||
|
||||
|
|
|
@ -118,5 +118,7 @@ class CustomUserDetailsSerializer(UserDetailsSerializer):
|
|||
|
||||
# Remove `pk` field from the response
|
||||
representation.pop('pk', None)
|
||||
# Remove the email field
|
||||
representation.pop('email', None)
|
||||
|
||||
return representation
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue