Answer the question
In order to leave comments, you need to log in
How to serialize a django model as a list?
class HistoryView(ListAPIView):
permission_classes = (IsAuthenticated,)
serializer_class = serializers.private.HistorySerializer
model = serializer_class.Meta.model
def get_queryset(self):
user = self.request.user
queryset = self.model.objects.filter(Q(user_1=user) | Q(user_2=user))
return queryset
class HistorySerializer(ModelSerializer):
class Meta:
model = models.exchange.History
fields = [
'date',
'type',
'name',
]
[
{
"date": 1555690476.155725,
"type": false,
"name": "name",
},
.......
.......
]
[
[1555690476.155725, false, "name"],
[...],
...
],
Answer the question
In order to leave comments, you need to log in
override the serializer method to_representation(self, obj) like this
def to_representation(self, obj):
return [obj.id, obj.date, obj.name]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question