如何在JsonResponse中格式化并返回查询中的所有项?我不明白这个错误。
这是查询的结果
TypeError at /api/driver/orders/ready/
'tuple' object is not callable
/apis.py in driver_get_ready_orders
@csrf_exempt
def driver_get_ready_orders(request):
driver = CustomJWTAuthenticator().authenticate(request)[0].driver
queryset = Order.objects.filter(
status=Order.READY, driver=None).order_by("-id"),
if driver.dispensary:
queryset = queryset(dispensary=driver.dispensary ...
)
orders = Order.objects.filter(
queryset,
many=True,
context={"request": request}
ⶠLocal vars
Variable Value
driver
<Driver: Malcom Brooks>
queryset
(<QuerySet [<Order: 10>, <Order: 8>]>,)
request
<WSGIRequest: GET '/api/driver/orders/ready/?
def driver_get_ready_orders(request):
driver = CustomJWTAuthenticator().authenticate(request)[0].driver
queryset = Order.objects.filter(
status=Order.READY, driver=None).order_by("-id"),
if driver.dispensary:
queryset = queryset(dispensary=driver.dispensary
).all()
orders = Order.objects.filter(
queryset,
many=True
)
return JsonResponse({"orders": orders.data})
订单和驱动程序型号:
class Order(models.Model):
PICKING = 1
READY = 2
ONTHEWAY = 3
DELIVERED = 4
CANCELED = 5
STATUS_CHOICES = (
(PICKING, "Your Order Is Being Picked Right Off The Plant!"),
(READY, "Picked, Weighed, And Ready For Delivery."),
(ONTHEWAY, "The Best Bud Is Heading Straight To Your Door."),
(DELIVERED, "Delivered"),
(CANCELED, "Canceled/Refunded")
)
address = models.CharField(max_length=500)
customer = models.ForeignKey(CustomerDetails, on_delete=models.CASCADE)
dispensary = models.ForeignKey(Dispensary, on_delete=models.CASCADE)
driver = models.ForeignKey(
Driver, blank=True, null=True, on_delete=models.CASCADE)
status = models.IntegerField(choices=STATUS_CHOICES)
def __str__(self):
return str(self.id)
class Driver(models.Model):
Active_License = (
('License_Status', (
('active', 'Active'),
('suspended', 'Suspended')
)),
)
address = models.CharField(max_length=500, blank=True)
name = models.CharField(max_length=500, default='')
phone = models.CharField(max_length=500, blank=True)
photo = models.ImageField(
upload_to='driver_photos/', blank=False, default='')
user = models.OneToOneField(
User, on_delete=models.CASCADE, related_name='driver')
dispensary = models.ForeignKey(
Dispensary, null=True, blank=True, on_delete=models.CASCADE)
def __str__(self):
return self.user.get_full_name()