Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
create()接受1个位置参数,但python中提供了2个位置参数_Python_Python 3.x_Django_Django Models_Django Views - Fatal编程技术网

create()接受1个位置参数,但python中提供了2个位置参数

create()接受1个位置参数,但python中提供了2个位置参数,python,python-3.x,django,django-models,django-views,Python,Python 3.x,Django,Django Models,Django Views,models.py class UserAttributes(models.Model): airport = models.ForeignKey('airport.Airport', related_name='user_attributes_airport', on_delete=models.SET_NULL, null=True, blank=True) location = PointField(blank=True, null=True) user = m

models.py

class UserAttributes(models.Model):

    airport = models.ForeignKey('airport.Airport', related_name='user_attributes_airport', on_delete=models.SET_NULL, null=True, blank=True)
    location = PointField(blank=True, null=True)
    user =  models.ForeignKey(
        'users.AerosimpleUser', related_name='user_attributes',
        on_delete=models.CASCADE, null=True, blank=True)
views.py

class LocationViewSet(viewsets.ModelViewSet):

    serializer_class=LocationRetrieveSerializer
    http_method_names = ['get', 'post', 'patch', 'put']

    def get_permissions(self):
            switcher = {
                'create': [IsAuthenticated],
                'list': [IsAuthenticated],
                'retrieve': [IsAuthenticated],
                'update': [IsAuthenticated],
                'partial_update': [IsAuthenticated],
            }
            self.permission_classes = switcher.get(self.action, [IsAdminUser])
            return super(self.__class__, self).get_permissions()
    def get_queryset(self):
        return UserAttributes.objects.filter(
            airport__id=self.request.user.aerosimple_user.airport_id).order_by('pk')
序列化程序.py

class LocationRetrieveSerializer(serializers.ModelSerializer):

    class Meta:
        model = UserAttributes
        fields = '__all__'

    def create(self, validated_data):
    

        if UserAttributes.objects.filter(user_id=self.context["request"].data['user'],airport_id=self.context["request"].data['airport']).exists():
            obj=UserAttributes.objects.get(user_id=self.context["request"].data['user'])
            obj.location=self.context["request"].data['location']
            obj.save()
            return obj
        user_attributes = UserAttributes.objects.create(validated_data)
        return user_attributes

在返回
验证的\u数据之前,我应该使用drf文档作为参考,对其进行哪些更改

    def create(self, validated_data):
    

        if UserAttributes.objects.filter(user_id=self.context["request"].data['user'],airport_id=self.context["request"].data['airport']).exists():
            obj=UserAttributes.objects.get(user_id=self.context["request"].data['user'])
            obj.location=self.context["request"].data['location']
            obj.save()
            return obj
        user_attributes = UserAttributes.objects.create(**validated_data)

请将完整的错误回溯添加到您的问题中!