[Django]-Remove keys from array in django rest framework serializer

0πŸ‘

βœ…

For genres: You can use values_list.

Try this in your get_genres:

def get_genres(self, obj):
    return MovieGenre.objects.filter(movie=obj).values_list('genre', flat=True)

I assume that the genre is the field name of MovieGenre model.

And for the movie key – as it is currently in your question – there should not be any movie key. Your serializer does not have it. So i cant see why you have the output unless there is something else you did not include.

The serializer should producer list of serialized movie objects.

Try to remove StandardResultsSetPagination and see if it is correct.

Leave a comment