I am learning DRF now, im little puzzuled by this many = True
code. What does it do? Or what does it mean?
example 1
class AlbumSerializer(serializers.ModelSerializer):
tracks = serializers.RelatedField(many=True)
class Meta:
model = Album
fields = ('album_name', 'artist', 'tracks')
example 2
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = (IsAdminUser,)
def list(self, request):
# Note the use of `get_queryset()` instead of `self.queryset`
queryset = self.get_queryset()
serializer = UserSerializer(queryset, many=True)
return Response(serializer.data)
many - If applied to a to-many relationship, you should set this argument to True.
then in serializers its writtenTo serialize a queryset or list of objects instead of a single object instance, you should pass the many=True
... one code but two different explanations is making me confused..