从自定义字段模型中获取所有字段

时间:2018-03-27 18:45:11

标签: python django

我有一个模特:

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"
            ],

1 个答案:

答案 0 :(得分:0)

由于managers = UsersInCompanySerializer(many=True, queryset=User.objects.all().filter(groups__name='manager'))

,这种情况正在发生

正如您在字段列表中提到的管理员所以间接地显示了UsersInCompanySerializer

中的所有字段