Как я могу получить ответ в формате массива в Django drf?Я новичок в программировании на python-drf.Пожалуйста, помогите с решениями.
Я просто хочу team_users в формате массива, но теперь он возвращается в массиве с каждой буквой, разделенной кавычками.
{
"id": 3,
"team_name": "team 3",
"team_icon": "/media/icon/underground_3Dz5sfD.png",
"team_users": [
"[",
"'",
"s",
"k",
"a",
"r",
"a",
"n",
"7",
"1",
"4",
"@",
"g",
"m",
"a",
"i",
"l",
".",
"c",
"o",
"m",
"'",
",",
" ",
"'",
"s",
"a",
"m",
"p",
"l",
"e",
"1",
"2",
"3",
"@",
"g",
"m",
"a",
"i",
"l",
".",
"c",
"o",
"m",
"'",
"]"
]
},
требуемый формат:
"id": 3,
"team_name": "team 3",
"team_icon": "/media/icon/underground_3Dz5sfD.png",
"team_users": ["first_email", "second_email"]
Это код в serializers.py
class TeamSerializer(serializers.ModelSerializer):
team_users = serializers.ListField(child=serializers.EmailField(min_length=0, max_length=100))
class Meta():
model=Team
fields = ('id','team_name', 'team_icon', 'team_users')
models.py
class Team(models.Model):
team_name = models.CharField(max_length=255)
team_icon = models.ImageField()
team_users = models.EmailField()
Вviews.py
class GetTeam(APIView):
def get(self, request, *args, **kwargs):
data_list = []
teams = models.Team.objects.all()
for team in teams:
data_list.append(serializers.TeamSerializer(team).data)
return Response(data_list)