我有一个模特:
server.js
查看
Actions_single_PVC.js
串行
class Companies(models.Model):
..
managers = models.ManyToManyField(User, related_name="managers", blank=True)
但是当我收到JSON时,我的字段class CompaniesList(generics.ListCreateAPIView):
queryset = Companies.objects.all()
serializer_class = CompaniesSerializer
permission_classes = (permissions.IsAuthenticated,)
只有class UsersInCompanySerializer(PrimaryKeyRelatedField, serializers.ModelSerializer):
class Meta:
model = User
fields = ('id',
'first_name',
'last_name',
'email',
'is_active',
'is_staff',
'last_login',
'created_date')
class CompaniesSerializer(serializers.ModelSerializer):
managers = UsersInCompanySerializer(many=True, queryset=User.objects.all().filter(groups__name='manager'))
class Meta:
model = Companies
fields = ('id', 'managers', .....)
,就像这样:
managers
如何查看id
中的所有字段,如下所示:
"managers": [
"6b7f40f2-73a7-43cb-b1b7-4e24374495e8"
],
答案 0 :(得分:0)
由于managers = UsersInCompanySerializer(many=True, queryset=User.objects.all().filter(groups__name='manager'))
正如您在字段列表中提到的管理员所以间接地显示了UsersInCompanySerializer