コード例 #1
0
class TripSerializer(serializers.ModelSerializer):
    city = CitySerializer(many=False, read_only=True)
    users = UserSerializer(many=True, read_only=True)

    class Meta:
        model = Trip
        fields = ('id', 'trip_name', 'city', 'users', 'start_date_tx')
コード例 #2
0
class NotificationSerializer(serializers.ModelSerializer):
    initiator_user = UserSerializer(many=False, read_only=True)
    trip = TripSerializer(many=False, read_only=True)

    class Meta(object):
        model = Notification
        fields = ('id', 'initiator_user', 'notification_type', 'text',
                  'created_at', 'is_read', 'trip')
コード例 #3
0
def get_user_profile(request):
    """
    Returns user object using user email address
    :param request:
    :param email:
    :return: 200 successful
    """
    serializer = UserSerializer(request.user)
    return Response(serializer.data)
コード例 #4
0
def get_users_by_email(request, email):
    """
    Returns user object using user email address
    :param request:
    :param email:
    :return: 200 successful
    """
    users = User.objects.filter(is_staff=False, is_superuser=False, username__startswith=email)[:5]
    serializer = UserSerializer(users, many=True)
    return Response(serializer.data)
コード例 #5
0
def get_user_by_id(request, user_id):
    """
    Returns user object using user id
    :param request:
    :param user_id:
    :return: 400 if incorrect user ID is sent
    :return: 200 successful
    """
    try:
        user = User.objects.get(pk=user_id)
    except User.DoesNotExist:
        error_message = "Invalid user ID"
        return Response(error_message, status=status.HTTP_400_BAD_REQUEST)
    serializer = UserSerializer(user)
    return Response(serializer.data)
コード例 #6
0
ファイル: views.py プロジェクト: arunikayadav42/server
def trip_friends_all(request):
    """
    Returns a list of friends user had been to trip
    :param request:
    :return: 200 successful
    """
    try:
        all_trips = User.objects.filter(trip__users=request.user).distinct()

    except User.DoesNotExist:
        error_message = "Trip does not exist"
        return Response(error_message, status=status.HTTP_404_NOT_FOUND)
    except Exception as e:
        return Response(str(e), status=status.HTTP_400_BAD_REQUEST)

    serializer = UserSerializer(all_trips, many=True)
    return Response(serializer.data)
コード例 #7
0
class FeedbackCondensedSerializer(serializers.ModelSerializer):
    user = UserSerializer(read_only=True)

    class Meta:
        model = Feedback
        fields = ('id', 'type', 'created', 'user')