Python 从url传递序列化程序的参数
我有:Python 从url传递序列化程序的参数,python,Python,我有: class ListCheckInOutJobApplyScheduleInOutView(APIView): permission_classes = (IsAuthenticated,) def get_queryset(self): user = self.request.user if user.is_authenticated: check = JobApply.objects.filter(UserID
class ListCheckInOutJobApplyScheduleInOutView(APIView):
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
if user.is_authenticated:
check = JobApply.objects.filter(UserIDEmployeeJobApply=user) | \
JobApply.objects.filter(UserIDEmployerJobApply=user)
if check:
return check
raise PermissionDenied()
def get(self, request, idjobapply, idschedule, idinout):
jobapply = JobApply.objects.filter(id=idjobapply).get(ScheduleIDJobApply=idschedule)
if jobapply is None:
return Response({"error": "Given question object not found."}, status=404)
schedule = Schedule.objects.get(id=idschedule)
if schedule is None:
return Response({"error": "Given question object not found."}, status=404)
serailizerschedule = ListScheduleCheckInOutSerializerInOut(schedule)
return Response(serailizerschedule.data)
class ListInOutSerializerInOut(serializers.ModelSerializer):
inoutidcheckinout = ListCheckInOutSerializerInOut(many=True, required=False)
class Meta:
model = InOut
fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
read_only_fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
class ListDaInOutSerializerInOut(serializers.ModelSerializer):
inoutdate = serializers.SerializerMethodField(method_name='get_inout')
class Meta:
model = DateInOut
fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
read_only_fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
def get_inout(self, obj):
myVariable = self.context['request'].query_params.get('idinout', None)
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
path('ListCheckInOutJobApplyScheduleInOutView/<int:idjobapply>/<int:idschedule>/*<int:idinout>*/', ListCheckInOutJobApplyScheduleInOutView.as_view(),
name="ListCheckInOutJobApplyScheduleInOutView"),
def get_inout(self, obj):
*myVariable = self.context['request'].query_params.get('idinout', None)*
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
网址:
class ListCheckInOutJobApplyScheduleInOutView(APIView):
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
if user.is_authenticated:
check = JobApply.objects.filter(UserIDEmployeeJobApply=user) | \
JobApply.objects.filter(UserIDEmployerJobApply=user)
if check:
return check
raise PermissionDenied()
def get(self, request, idjobapply, idschedule, idinout):
jobapply = JobApply.objects.filter(id=idjobapply).get(ScheduleIDJobApply=idschedule)
if jobapply is None:
return Response({"error": "Given question object not found."}, status=404)
schedule = Schedule.objects.get(id=idschedule)
if schedule is None:
return Response({"error": "Given question object not found."}, status=404)
serailizerschedule = ListScheduleCheckInOutSerializerInOut(schedule)
return Response(serailizerschedule.data)
class ListInOutSerializerInOut(serializers.ModelSerializer):
inoutidcheckinout = ListCheckInOutSerializerInOut(many=True, required=False)
class Meta:
model = InOut
fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
read_only_fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
class ListDaInOutSerializerInOut(serializers.ModelSerializer):
inoutdate = serializers.SerializerMethodField(method_name='get_inout')
class Meta:
model = DateInOut
fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
read_only_fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
def get_inout(self, obj):
myVariable = self.context['request'].query_params.get('idinout', None)
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
path('ListCheckInOutJobApplyScheduleInOutView/<int:idjobapply>/<int:idschedule>/*<int:idinout>*/', ListCheckInOutJobApplyScheduleInOutView.as_view(),
name="ListCheckInOutJobApplyScheduleInOutView"),
def get_inout(self, obj):
*myVariable = self.context['request'].query_params.get('idinout', None)*
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
从url传递序列化程序的参数
路径('ListCheckInOutJobApplyScheduleInOutView/int:idjobapply/int:idschedule/int:idOut/',ListCheckInOutJobApplyScheduleInOutView.as_view(),
name=“ListCheckInOutJobApplyScheduleInOutView”)
查看:
class ListCheckInOutJobApplyScheduleInOutView(APIView):
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
if user.is_authenticated:
check = JobApply.objects.filter(UserIDEmployeeJobApply=user) | \
JobApply.objects.filter(UserIDEmployerJobApply=user)
if check:
return check
raise PermissionDenied()
def get(self, request, idjobapply, idschedule, idinout):
jobapply = JobApply.objects.filter(id=idjobapply).get(ScheduleIDJobApply=idschedule)
if jobapply is None:
return Response({"error": "Given question object not found."}, status=404)
schedule = Schedule.objects.get(id=idschedule)
if schedule is None:
return Response({"error": "Given question object not found."}, status=404)
serailizerschedule = ListScheduleCheckInOutSerializerInOut(schedule)
return Response(serailizerschedule.data)
class ListInOutSerializerInOut(serializers.ModelSerializer):
inoutidcheckinout = ListCheckInOutSerializerInOut(many=True, required=False)
class Meta:
model = InOut
fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
read_only_fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
class ListDaInOutSerializerInOut(serializers.ModelSerializer):
inoutdate = serializers.SerializerMethodField(method_name='get_inout')
class Meta:
model = DateInOut
fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
read_only_fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
def get_inout(self, obj):
myVariable = self.context['request'].query_params.get('idinout', None)
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
path('ListCheckInOutJobApplyScheduleInOutView/<int:idjobapply>/<int:idschedule>/*<int:idinout>*/', ListCheckInOutJobApplyScheduleInOutView.as_view(),
name="ListCheckInOutJobApplyScheduleInOutView"),
def get_inout(self, obj):
*myVariable = self.context['request'].query_params.get('idinout', None)*
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
序列化程序:
class ListCheckInOutJobApplyScheduleInOutView(APIView):
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
if user.is_authenticated:
check = JobApply.objects.filter(UserIDEmployeeJobApply=user) | \
JobApply.objects.filter(UserIDEmployerJobApply=user)
if check:
return check
raise PermissionDenied()
def get(self, request, idjobapply, idschedule, idinout):
jobapply = JobApply.objects.filter(id=idjobapply).get(ScheduleIDJobApply=idschedule)
if jobapply is None:
return Response({"error": "Given question object not found."}, status=404)
schedule = Schedule.objects.get(id=idschedule)
if schedule is None:
return Response({"error": "Given question object not found."}, status=404)
serailizerschedule = ListScheduleCheckInOutSerializerInOut(schedule)
return Response(serailizerschedule.data)
class ListInOutSerializerInOut(serializers.ModelSerializer):
inoutidcheckinout = ListCheckInOutSerializerInOut(many=True, required=False)
class Meta:
model = InOut
fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
read_only_fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
class ListDaInOutSerializerInOut(serializers.ModelSerializer):
inoutdate = serializers.SerializerMethodField(method_name='get_inout')
class Meta:
model = DateInOut
fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
read_only_fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
def get_inout(self, obj):
myVariable = self.context['request'].query_params.get('idinout', None)
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
path('ListCheckInOutJobApplyScheduleInOutView/<int:idjobapply>/<int:idschedule>/*<int:idinout>*/', ListCheckInOutJobApplyScheduleInOutView.as_view(),
name="ListCheckInOutJobApplyScheduleInOutView"),
def get_inout(self, obj):
*myVariable = self.context['request'].query_params.get('idinout', None)*
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
问题:
我想通过函数get\u inout从序列化程序中的URL传递参数:
网址:
class ListCheckInOutJobApplyScheduleInOutView(APIView):
permission_classes = (IsAuthenticated,)
def get_queryset(self):
user = self.request.user
if user.is_authenticated:
check = JobApply.objects.filter(UserIDEmployeeJobApply=user) | \
JobApply.objects.filter(UserIDEmployerJobApply=user)
if check:
return check
raise PermissionDenied()
def get(self, request, idjobapply, idschedule, idinout):
jobapply = JobApply.objects.filter(id=idjobapply).get(ScheduleIDJobApply=idschedule)
if jobapply is None:
return Response({"error": "Given question object not found."}, status=404)
schedule = Schedule.objects.get(id=idschedule)
if schedule is None:
return Response({"error": "Given question object not found."}, status=404)
serailizerschedule = ListScheduleCheckInOutSerializerInOut(schedule)
return Response(serailizerschedule.data)
class ListInOutSerializerInOut(serializers.ModelSerializer):
inoutidcheckinout = ListCheckInOutSerializerInOut(many=True, required=False)
class Meta:
model = InOut
fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
read_only_fields = ('id',
'UserIDInOut',
'EmployerIDInOut',
'ScheduleIDInOut',
'DateInOutIDInOutSchedule',
'InOutName',
'TimeIn',
'TimeOut',
'inoutidcheckinout'
)
class ListDaInOutSerializerInOut(serializers.ModelSerializer):
inoutdate = serializers.SerializerMethodField(method_name='get_inout')
class Meta:
model = DateInOut
fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
read_only_fields = ('id',
'UserIDDateInOut',
'EmployerIDDateInOut',
'ScheduleIDDateInOut',
'DateIDInOut',
'inoutdate'
)
def get_inout(self, obj):
myVariable = self.context['request'].query_params.get('idinout', None)
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
path('ListCheckInOutJobApplyScheduleInOutView/<int:idjobapply>/<int:idschedule>/*<int:idinout>*/', ListCheckInOutJobApplyScheduleInOutView.as_view(),
name="ListCheckInOutJobApplyScheduleInOutView"),
def get_inout(self, obj):
*myVariable = self.context['request'].query_params.get('idinout', None)*
print(myVariable)
checkinout = InOut.objects.get(id=myVariable)
# if not checkinout:
# return {}
inout = InOut.objects.filter(InOutName=checkinout.InOutName, TimeIn=checkinout.TimeIn,
TimeOut=checkinout.TimeOut)
# if not inout:
# return {}
data = ListInOutSerializerInOut(inout, many=True).data
return data
请帮帮我!谢谢强>