As I see in your code, I think you misunderstood the RetrieveAPIView. You 
cannot get a single object while giving multiple objects. If you create a 
RetrieveAPIView, you need to know which object is selected. I mean, you 
need to pass the ID of RokuContentFeed to your get method of 
RokuContentFeedRetrieveAPI.

code:

```
class RokuContentFeedListAPI(APIView):
   def get(self, request, format=None): 
       feeds = RokuContentFeed.objects.all().filter(is_public=True)
       serializer = RokuContentFeedSerializer(feeds, many=True)
       return Response(serializer.data) 
```

class RokuContentFeedRetrieveApi(APIView):
    def get(self, request, pk, format=None):
           feed = RokuContentFeed.objects.get(pk=pk)
           serializer = RokuContentFeedSerializer(feed)
           return Response(serializer.data) 
```
class RokuContentFeedSerializer(serializers.ModelSerializer):
   providerName = serializers.CharField(source='provider_name')
   language = serializers.StringRelatedField()
   rating = RatingSerializerList()
   lastUpdated = serializers.DateTimeField(source='last_updated')
   movies = MovieSerializerList(many=True)
   liveFeeds = LiveFeedSerializerList(many=True, source='live_feeds')
   series = SeriesSerializerList(many=True)
   shortFormVideos = ShortFormVideoSerializerList(many=True, 
source='short_form_videos')
   tvSpecials = TVSpecialSerializerList(many=True, source='tv_specials')
   categories = CategorySerializerList(many=True)
   playlists = PlaylistSerializerList(many=True)
   class Meta:
       model = RokuContentFeed
       #read_only_fields = ['is_public']
       fields = ['providerName', 'language', 'rating', 'lastUpdated', 
'movies', \
           'liveFeeds', 'series', 'shortFormVideos', 'tvSpecials', 
'categories', 'playlists']
```


19 Kasım 2023 Pazar tarihinde saat 03:37:28 UTC+3 itibarıyla : Anthony: 
Crawford. şunları yazdı:

> Thank you, yes, many=True will turn any field a list. However my issue is 
> that this response data is the main object. It is returning a list of 
> objects [ { } ] instead of one object { }. I changed my view to contain 
> this code for now, but its defintely not a final solution. This code will 
> return a single { } object.
>
> ```
> class RokuContentFeedListAPI(APIView):
> renderer_classes = [JSONRenderer]
> pagination_class = None
> def get(self, request, format=None):
> feeds = RokuContentFeed.objects.first()
> serializer = RokuContentFeedSerializerList(feeds)
> return Response(serializer.data)
> ```
>
> On Friday, November 3, 2023 at 8:42:38 AM UTC-3 leonardo....@franq.com.br 
> wrote:
>
>> hi Anthony, as i know, the "many" parameter in your 
>> RokuContentFeedSerializer method makes your data an array [ ]. 
>>
>> Em qua., 1 de nov. de 2023 às 19:10, : Anthony: Crawford. <
>> crawfi...@gmail.com> escreveu:
>>
>>> Hi,
>>> I am trying to create an API that will provide JSON data that is based 
>>> on Roku JSON specification (
>>> https://developer.roku.com/en-ca/docs/specs/direct-publisher-feed-specs/json-dp-spec.md
>>> ).
>>> The specification requires that the JSON data is a single object { }, 
>>> not a list array [ ].
>>> So far I am not able to setup the APIView to render JSON data as an 
>>> object { }.
>>>
>>> The ListAPIView always serializes the JSON to an array and not a single 
>>> object. However, RetrieveAPIView serializes the JSON as a single object.
>>>
>>> A sample of the Roku JSON feed:
>>> https://devtools.web.roku.com/samples/roku-developers-feed-v1-rdp.json
>>>
>>> I am fairly new to this, and learning as I go. 
>>>
>>> code:
>>>
>>> ```
>>> class RokuContentFeedAPI(APIView):
>>> def get(self, request, format=None): 
>>> feed = RokuContentFeed.objects.all().filter(is_public=True)
>>> serializer = RokuContentFeedSerializer(feed, many=True)
>>> return Response(serializer.data) 
>>> ```
>>>
>>> ```
>>> class RokuContentFeedSerializer(serializers.ModelSerializer):
>>> providerName = serializers.CharField(source='provider_name')
>>> language = serializers.StringRelatedField()
>>> rating = RatingSerializerList()
>>> lastUpdated = serializers.DateTimeField(source='last_updated')
>>> movies = MovieSerializerList(many=True)
>>> liveFeeds = LiveFeedSerializerList(many=True, source='live_feeds')
>>> series = SeriesSerializerList(many=True)
>>> shortFormVideos = ShortFormVideoSerializerList(many=True, 
>>> source='short_form_videos')
>>> tvSpecials = TVSpecialSerializerList(many=True, source='tv_specials')
>>> categories = CategorySerializerList(many=True)
>>> playlists = PlaylistSerializerList(many=True)
>>> class Meta:
>>> model = RokuContentFeed
>>> #read_only_fields = ['is_public']
>>> fields = ['providerName', 'language', 'rating', 'lastUpdated', 'movies', 
>>> \
>>> 'liveFeeds', 'series', 'shortFormVideos', 'tvSpecials', 'categories', 
>>> 'playlists']
>>> ```
>>> Thank for any suggestions
>>> AC
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django REST framework" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-rest-fram...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-rest-framework/56f7c360-4ac4-4229-b0bd-effbd68d9b37n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-rest-framework/56f7c360-4ac4-4229-b0bd-effbd68d9b37n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/c02f7ab8-7ab5-40ea-b5c9-883647b9ec34n%40googlegroups.com.

Reply via email to