Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django REST framework tuple being interpreted as a string?

I've created the following serializer:

class KeywordSerializer(serializers.HyperlinkedModelSerializer):      

    class Meta:                                                                    
        model = Keyword                                                            
        fields = ('my_field')

However, when I try to use it in a viewset, I get the following error:

The fields option must be a list or tuple or "__all__". Got str.

But the issue is, fields is a tuple. I've even tried setting it to all or a list, but I get the same error. The same error occurs regardless of the name of the field.

Would anyone know why this happens?

like image 460
Cisplatin Avatar asked Feb 27 '16 22:02

Cisplatin


1 Answers

Yes, in Python ('my_field') is a string. To make a single-element tuple you need a comma: ('my_field',).

Note this is nothing to do with DRF.

like image 50
Daniel Roseman Avatar answered Sep 24 '22 05:09

Daniel Roseman