S
Size: a a a
S
S
BK
BK
S
BK
BK
S
BK
S
BK
BK
S
S
BK
BK
mytables = Table.objects.filter(order_table__date=date)
S
from django.db.models import Countпоидее должно вернуть столы у кот есть ордер, но могу ошибаться))
from django.db.models import Q
Table.objects.annotate(cnt=Count('order_table', filter=Q(order_table__date=date))).filter(cnt__gt=0)
BK
from django.db.models import Countпоидее должно вернуть столы у кот есть ордер, но могу ошибаться))
from django.db.models import Q
Table.objects.annotate(cnt=Count('order_table', filter=Q(order_table__date=date))).filter(cnt__gt=0)
def check_free_tables(request):
from django.db.models import Count
from django.db.models import Q
if request.is_ajax and request.method == 'GET':
date = request.GET.get('date')
mytables = Table.objects.annotate(cnt=Count('order_table', filter=Q(order_table__date=date))).filter(cnt__gt=0)
print(mytables)
ser_instance = serializers.serialize('json', list(mytables), fields=('id', 'is_reserved'))
print(ser_instance)
return JsonResponse({'tables': ser_instance}, status=200, safe=False)
S
print(Table.objects.annotate(cnt=Count('order_table', filter=Q(order_table__date=date))).filter(cnt__gt=0).query)
BK
print(Table.objects.annotate(cnt=Count('order_table', filter=Q(order_table__date=date))).filter(cnt__gt=0).query)
SELECT "restaurant_table"."id", "restaurant_table"."hall_id", "restaurant_table"."shape", "restaurant_table"."number", "restaurant_table"."seats", "restaurant_table"."width", "restaurant_table"."height", "restaurant_table"."coordinate_x", "restaurant_table"."coordinate_y", "restaurant_table"."is_reserved", C
OUNT(CASE WHEN "restaurant_order"."date" IS NULL THEN "restaurant_order"."id" ELSE NULL END) AS "cnt" FROM "restaurant_table" LEFT OUTER JOIN "restaurant_order" ON ("restaurant_table"."id" = "restaurant_order"."table_id") GROUP BY "restaurant_table"."id", "restaurant_table"."hall_id", "restaurant_table"."sha
pe", "restaurant_table"."number", "restaurant_table"."seats", "restaurant_table"."width", "restaurant_table"."height", "restaurant_table"."coordinate_x", "restaurant_table"."coordinate_y", "restaurant_table"."is_reserved" HAVING COUNT(CASE WHEN ("restaurant_order"."date" IS NULL) THEN "restaurant_order"."id"
ELSE NULL END) > 0